首页 \ 问答 \ 点击后如何打开离子模式?(How to open up an Ionic Modal upon click?)

点击后如何打开离子模式?(How to open up an Ionic Modal upon click?)

我是Ionic和AugularJS的新手,在点击设置页面中的第三个选项进行hashtag search的复选框/单选按钮时,我遇到了打开模式框的问题。 我已经包含一个ng-controllerng-click来采取行动。 我看着调试器,它显示一个错误:

GET http://localhost:8100/hashtag-modal [HTTP/1.1 404 Not Found 1ms]

我知道404未找到意味着它没有找到templateUrl,但我拥有的每个导航页面都在index.html中,并且除了app.js文件中的hashtag-modal.html外,它们hashtag-modal.html正常工作。 为什么它不工作,我该如何解决这个问题?

app.js

// Navigation pages
app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
  .state('index', {
    url: '/index',
    templateUrl: 'index.html'
  })
  .state('about', {
    url: '/about',
    templateUrl: 'about.html'
  })
  .state('settings', {
    url: '/settings',
    templateUrl: 'settings.html'
  })
  .state('hashtag-modal', {
    url: '/hashtag-modal',
    templateUrl: 'hashtag-modal',
    controller: 'hashtag-modalCtrl'
  })

  $urlRouterProvider.otherwise("/index"); // if no url found, go back to index
})

// Hashtag Search option
app.controller('hashtagController', ['$scope', function($scope)
                                     {
                                         $scope.hashtagValue = 'Search'; // default value

                                         $scope.hashtag = function()
                                         {
                                             $scope.hashtagValue = 'blackandwhitephotography'; // if selected, it'll display this value


                                         };

                                     }]);

// hashtag search modal
app.controller('hashtag-modalCtrl', function($scope, $ionicModal) {
    $ionicModal.fromTemplateUrl('hashtag-modal.html', {
        scope: $scope,
        animation: 'slide-in-up',
        focusFirstInput: true
    }).then(function(modal) {
        $scope.modal = modal;
    });
    $scope.openModal = function() {
        $scope.modal.show();
    };
    $scope.closeModal = function() {
        $scope.modal.hide();
    };
    // Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function() {
        $scope.modal.remove();
    });
    // Execute action on hide modal
    $scope.$on('modal.hidden', function() {
        // Execute action
    });
    // Execute action on remove modal
    $scope.$on('modal.removed', function() {
        // Execute action
    });
});

的index.html

<!-- SETTINGS -->
<script id="settings.html" type="text/ng-template">
  <!-- The title of the ion-view will be shown on the navbar -->
  <ion-view title="Settings" hide-back-button="false">
    <ion-content class="padding">
      <!-- The content of the page -->
        <p>Check one of the options below to set how you wish to categorize and view your Instagram photos.
        </p>
        <div class="settings-list">
            <label class="item item-radio">
                <input type="radio" name="settings-group" value="recent">
                <div class="item-content">
                    Recent
                </div>
                <i class="radio-icon ion-checkmark"></i>
            </label>
            <label class="item item-radio">
                <input type="radio" name="settings-group" value="popular">
                <div class="item-content">
                    Most Popular
                </div>
                <i class="radio-icon ion-checkmark"></i>
            </label>
            <label class="item item-radio" id="hashtagRadio" ng-controller="hashtagController" ng-click="hashtag();modal.show();">
                <input type="radio" name="settings-group" value="search">
                <div class="item-content">
                    <span class="ion-pound"></span>&nbsp;&nbsp;&nbsp;<span id="hashtagInput">{{hashtagValue}}</span>
                </div>
                <i class="radio-icon ion-checkmark"></i>
            </label>
        </div>
    </ion-content>
  </ion-view>
</script>     

<!-- HASHTAG SEARCH MODAL -->
<script id="hashtag-modal.html" type="text/ng-template">
  <ion-modal-view hide-back-button="false">
    <ion-header-bar>
      <h1 class="title">Hashtag Search</h1>
    </ion-header-bar>
    <ion-content>
      <label class="item item-input">
        <i class="icon ion-search placeholder-icon"></i>
        <input type="search" placeholder="Search">
      </label>
    </ion-content>
  </ion-modal-view>
</script>

修改后的app.js

我在hashtagController添加了一个$ionicModal ,但据说Error: $ionicModal is undefined 。 还有哪些地方没有定义?

// Hashtag Search option
app.controller('hashtagController', ['$scope', function($scope, $ionicModal)
{
  $scope.hashtagValue = 'Search'; // default value

  $scope.hashtag = function()
  {
    $scope.hashtagValue = 'blackandwhitephotography'; // if selected, it'll display this value
    $ionicModal.fromTemplateUrl('hashtag-modal.html', {
        scope: $scope,
        animation: 'slide-in-up',
        focusFirstInput: true
    }).then(function(modal) {
        $scope.modal = modal;
    });
    $scope.openModal = function() {
        $scope.modal.show();
    };
    $scope.closeModal = function() {
        $scope.modal.hide();
    };
    // Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function() {
        $scope.modal.remove();
    });
    // Execute action on hide modal
    $scope.$on('modal.hidden', function() {
        // Execute action
    });
    // Execute action on remove modal
    $scope.$on('modal.removed', function() {
        // Execute action
    });


                                         }

                                     }]);

修订后的标签

<label class="item item-radio" id="hashtagRadio" ng-controller="hashtagController" ng-click="hashtag();openModal();">
  <input type="radio" name="settings-group" value="search">
  <div class="item-content">
    <span class="ion-pound"></span>&nbsp;&nbsp;&nbsp;<span id="hashtagInput">{{hashtagValue}}</span>
  </div>
  <i class="radio-icon ion-checkmark"></i>
 </label>

I am new to Ionic and AugularJS and I am having a problem opening up a modal box upon click on a checkbox/radio button on the third option for hashtag search in the settings page. I have included an ng-controller and ng-click to take action. I looked in the debugger and it displayed an error:

GET http://localhost:8100/hashtag-modal [HTTP/1.1 404 Not Found 1ms]

I know that 404 Not Found means it didn't find the templateUrl but every nav page I have is in the index.html and they work fine except hashtag-modal.html in the app.js file. Why isn't it working and how do I resolve this issue?

app.js

// Navigation pages
app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
  .state('index', {
    url: '/index',
    templateUrl: 'index.html'
  })
  .state('about', {
    url: '/about',
    templateUrl: 'about.html'
  })
  .state('settings', {
    url: '/settings',
    templateUrl: 'settings.html'
  })
  .state('hashtag-modal', {
    url: '/hashtag-modal',
    templateUrl: 'hashtag-modal',
    controller: 'hashtag-modalCtrl'
  })

  $urlRouterProvider.otherwise("/index"); // if no url found, go back to index
})

// Hashtag Search option
app.controller('hashtagController', ['$scope', function($scope)
                                     {
                                         $scope.hashtagValue = 'Search'; // default value

                                         $scope.hashtag = function()
                                         {
                                             $scope.hashtagValue = 'blackandwhitephotography'; // if selected, it'll display this value


                                         };

                                     }]);

// hashtag search modal
app.controller('hashtag-modalCtrl', function($scope, $ionicModal) {
    $ionicModal.fromTemplateUrl('hashtag-modal.html', {
        scope: $scope,
        animation: 'slide-in-up',
        focusFirstInput: true
    }).then(function(modal) {
        $scope.modal = modal;
    });
    $scope.openModal = function() {
        $scope.modal.show();
    };
    $scope.closeModal = function() {
        $scope.modal.hide();
    };
    // Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function() {
        $scope.modal.remove();
    });
    // Execute action on hide modal
    $scope.$on('modal.hidden', function() {
        // Execute action
    });
    // Execute action on remove modal
    $scope.$on('modal.removed', function() {
        // Execute action
    });
});

index.html

<!-- SETTINGS -->
<script id="settings.html" type="text/ng-template">
  <!-- The title of the ion-view will be shown on the navbar -->
  <ion-view title="Settings" hide-back-button="false">
    <ion-content class="padding">
      <!-- The content of the page -->
        <p>Check one of the options below to set how you wish to categorize and view your Instagram photos.
        </p>
        <div class="settings-list">
            <label class="item item-radio">
                <input type="radio" name="settings-group" value="recent">
                <div class="item-content">
                    Recent
                </div>
                <i class="radio-icon ion-checkmark"></i>
            </label>
            <label class="item item-radio">
                <input type="radio" name="settings-group" value="popular">
                <div class="item-content">
                    Most Popular
                </div>
                <i class="radio-icon ion-checkmark"></i>
            </label>
            <label class="item item-radio" id="hashtagRadio" ng-controller="hashtagController" ng-click="hashtag();modal.show();">
                <input type="radio" name="settings-group" value="search">
                <div class="item-content">
                    <span class="ion-pound"></span>&nbsp;&nbsp;&nbsp;<span id="hashtagInput">{{hashtagValue}}</span>
                </div>
                <i class="radio-icon ion-checkmark"></i>
            </label>
        </div>
    </ion-content>
  </ion-view>
</script>     

<!-- HASHTAG SEARCH MODAL -->
<script id="hashtag-modal.html" type="text/ng-template">
  <ion-modal-view hide-back-button="false">
    <ion-header-bar>
      <h1 class="title">Hashtag Search</h1>
    </ion-header-bar>
    <ion-content>
      <label class="item item-input">
        <i class="icon ion-search placeholder-icon"></i>
        <input type="search" placeholder="Search">
      </label>
    </ion-content>
  </ion-modal-view>
</script>

Revised app.js

I added an $ionicModal to the hashtagController but it is said Error: $ionicModal is undefined. Where else is it undefined?

// Hashtag Search option
app.controller('hashtagController', ['$scope', function($scope, $ionicModal)
{
  $scope.hashtagValue = 'Search'; // default value

  $scope.hashtag = function()
  {
    $scope.hashtagValue = 'blackandwhitephotography'; // if selected, it'll display this value
    $ionicModal.fromTemplateUrl('hashtag-modal.html', {
        scope: $scope,
        animation: 'slide-in-up',
        focusFirstInput: true
    }).then(function(modal) {
        $scope.modal = modal;
    });
    $scope.openModal = function() {
        $scope.modal.show();
    };
    $scope.closeModal = function() {
        $scope.modal.hide();
    };
    // Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function() {
        $scope.modal.remove();
    });
    // Execute action on hide modal
    $scope.$on('modal.hidden', function() {
        // Execute action
    });
    // Execute action on remove modal
    $scope.$on('modal.removed', function() {
        // Execute action
    });


                                         }

                                     }]);

Revised label

<label class="item item-radio" id="hashtagRadio" ng-controller="hashtagController" ng-click="hashtag();openModal();">
  <input type="radio" name="settings-group" value="search">
  <div class="item-content">
    <span class="ion-pound"></span>&nbsp;&nbsp;&nbsp;<span id="hashtagInput">{{hashtagValue}}</span>
  </div>
  <i class="radio-icon ion-checkmark"></i>
 </label>

原文:https://stackoverflow.com/questions/27285472
更新时间:2019-06-10 06:28

最满意答案

我认为它还没有实现($ psise)。 您可以在VSCode的vscode-powershell Project上提出问题。 类似的一个已经提交。

至少你可以使用像$context = [Microsoft.Powershell.EditorServices.Extensions.EditorContext]$psEditor.GetEditorContext()

然后你可以访问当前文件... $context.CurrentFile.

有关介绍,另请参阅此视频 ...


I think it's not implemented yet (the $psise). You can file an issue on the vscode-powershell Project for VSCode. A similar one has already been filed.

At least you might use something like $context = [Microsoft.Powershell.EditorServices.Extensions.EditorContext]$psEditor.GetEditorContext()

Then you can access the current file... $context.CurrentFile.

See also this video for an introduction...

相关问答

更多
  • 我认为它还没有实现($ psise)。 您可以在VSCode的vscode-powershell Project上提出问题。 类似的一个已经提交。 至少你可以使用像$context = [Microsoft.Powershell.EditorServices.Extensions.EditorContext]$psEditor.GetEditorContext() 然后你可以访问当前文件... $context.CurrentFile. 有关介绍,另请参阅此视频 ... I think it's not i ...
  • Visual Studio(完整版)是一个“全功能”和“方便”的开发环境。 Visual Studio(免费的“Express”版本 - 直到2015年)是功能集中和完整版本的简化版本。 以不同版本(Visual Studio Web Developer,Visual Studio C#等)为特征为中心的意图取决于您的目标。 Visual Studio(免费社区版 - 自2015年以来)是完整版本的简化版本,取代了2015年之前使用的分开的快速版本。 Visual Studio代码(VSCode)是一个跨平 ...
  • 代码格式可通过以下快捷方式在VS代码中使用: 在Windows Shift + Alt + F 在Mac Shift + Option + F 在Ubuntu上Ctrl + Shift + I 或者,您可以通过Ctrl + Shift + P (或Mac上的Command + Shift + P )编辑器中提供的搜索功能找到快捷方式以及其他快捷方式,然后搜索格式文档 。 The code formatting is available in Visual Studio Code through the fo ...
  • 是的,有。 您可以选择Window> Preferences对话框来访问现有的那些。 然后导航到Java> Editor> Templates子树。 在那里你可以看到现有的。 第一列是名称和激活码。 例如,“main”模板在光标位置插入默认主块。 您可以在编辑器中输入“main”并按“CTRL + space”。 然后会显示一个弹出窗口,您可以选择所需的模板。 在上述对话框中,您既可以定义新模板,也可以随意编辑现有模板。 需要考虑的一件事是,如果光标位于第二列中指示的上下文中,则内容辅助(CTRL +空格键 ...
  • 你可以下载一个扩展程序,它可以做到这一点: 它还有一个快捷键。 http://visualstudiogallery.msdn.microsoft.com/41a0cc2f-eefd-4342-9fa9-3626855ca22a There is an extension you can download which will do just that: It has a shortcut key as well. http://visualstudiogallery.msdn.microsoft.com/ ...
  • 这个问题在这里和这里已经有了答案。 差异列表非常庞大。 Visual Studio Code是Microsoft为Windows,Linux和MacOS开发的源代码编辑器,重点在于编写代码,而不是处理调试,编译,测试,重构以及所有使Visual Studio更好的其他功能。 使用Visual Studio代码的人可能是Mac上的人,他们只会处理客户端技术(HTML / JS / CSS),并且不想安装Windows来执行此操作。 使用Windows并开发C#,F#或VB的用户将继续使用Visual Stud ...
  • 我会建议使用: Git Lens 。 UPDATE Now it's available: https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory until now it isn't supported, but can follow the thread for it: github
  • 不幸的是Javascript不支持这个。 您可以通过评论进行分离。 /*My Region (Name It)*/ your scripts /*End Region*/ 或者你可以看到这个线程如何做到这一点。 如何在javascript中实现区域/代码崩溃 Unfortunately Javascript don't support this. You can do the separation by comments. /*My Region (Name It)*/ your scripts /*En ...
  • Visual Studio Code使用Roslyn平台(参见此处 )。 与Visual Studio 2015相同。在Linux和OS X上使用Mono编译器。 IDE本身如果基本上是GitHub Atom的扩展(这很棒),当然,它甚至不会接近完整Visual Studio的强大功能。 但它非常干净,易于使用。 特别是新的ASP.NET 5 Web应用程序非常像Node.js / Angular / etc应用程序,许多人在Sublime和Atom等简单的编辑器中编写这些应用程序。 更新: 它周围的工具并 ...
  • Visual Studio(VS)和Visual Studio Code(VSCode)是完全不同的产品。 他们不是真正的竞争者。 VS是一个完整的IDE,带有编译器,调试器,库,项目模板等。它只能在Windows和MacOS机器上运行。 VSCode是一个专为编码人员设计的轻量级文本编辑器。 它支持许多不同的文件类型,可以附加到编译器和调试器,但它不附带任何编译器或库。 它在所有桌面平台上运行。 当您想要维护C#或C ++项目时,VSCode可以成为VS的良好伴侣。 如果您想编写JavaScript,Ty ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)