- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 AngularJS 1.5.3 编写一个应用程序。我正在使用 $ionicModal 服务向我的用户显示模式。
我想将我的代码移动到“controller as”语法中,但我不确定如何使用 $ionicModal 服务来做到这一点。
这是我的 Controller 代码:
(function () {
"use strict";
angular
.module('myApp')
.controller('myController', myController);
myController.$inject = [
'$scope',
'$ionicModal',
'myService'
];
function myController($scope, $ionicModal, myService) {
$scope.data = myService.data;
$scope.openModal = openModal;
$ionicModal.fromTemplateUrl('./myPath/modal.html', function ($ionicModal) {
$scope.modal = $ionicModal;
}, {
scope: $scope,
animation: 'slide-in-up'
});
$scope.$on('$destroy', function () {
$scope.modal.remove();
});
function openModal() {
$scope.modal.show();
};
}
})();
最佳答案
I want to move my code into the 'controller as' syntax but I am not sure how to do that with the $ionicModal service.
没有
Ionic 通过调用创建模态作用域:
var scope = options.scope && options.scope.$new() || $rootScope.$new(true);
当您使用 ControllerAs
时对于您的根 Controller ,假设您有 vm
范围的实例 (a.e vm = this;
)。
vm
不是 scope
!!!.
vm
只是对象,没有范围继承,它没有 .$new()
方法
所以我们不能写{scope: vm}
但只有{scope: $scope}
当然,您可以使用 Ionic 代码,但它可能会导致意外行为
关于javascript - 如何在 $ionic 模态中使用 'controller as' 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45208795/
我来自 Asp.Net 世界,试图理解 Angular State 的含义。 什么是 Angular 状态?它类似于Asp.Net中的ascx组件吗?是子页面吗?它类似于工作流程状态吗? 我听到很多人
我一直在寻找 3 态拨动开关,但运气不佳。 基本上我需要一个具有以下状态的开关: |开 |不适用 |关 | slider 默认从中间开始,一旦用户向左或向右滑动,就无法回到N/A(未回答)状态。 有人
我是一名优秀的程序员,十分优秀!