gpt4 book ai didi

javascript - 如何在 $ionic 模态中使用 'controller as' 语法

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:41:27 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com