Javascript-离子模态无法打开(TypeError:无法读取未定义的属性“ show”)?
作者:互联网
我正在为Android开发一个离子angularJs应用程序.我不知道为什么,但是在我所谓的homeController中,每当我尝试调用一个函数以向我显示$ionicModal时,都会给我一个错误…
TypeError: Cannot read property ‘show’ of undefined at
Scope.$scope.openModal (homeModule.js:18) at new
(homeModule.js:59) at Object.invoke (ionic.bundle.js:11994) at
$get.extend.instance (ionic.bundle.js:16247) at ionic.bundle.js:15502
at forEach (ionic.bundle.js:8155) at nodeLinkFn
(ionic.bundle.js:15501) at compositeLinkFn (ionic.bundle.js:14887) at
publicLinkFn (ionic.bundle.js:14766) at
IonicModule.controller.self.appendViewElement (ionic.bundle.js:47324)
我的控制器看起来像这样(开始):
app.controller('homeController', function($scope, $ionicPopup, $state, $ionicLoading, $rootScope, $ionicModal, mapFactory){
// Load the modal from the given template URL
$ionicModal.fromTemplateUrl('templates/loginModal.html', function($ionicModal) {
$scope.modal = $ionicModal;
console.log($scope.modal);
}, {
scope: $scope,
animation: 'slide-in-up',
backdropClickToClose: false,
hardwareBackButtonClose: false,
focusFirstInput: true
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
我已经尝试了许多不同的方法来使模式打开,有趣的是,每当我进入新的$state并返回时,它都会打开…但是当我刷新页面时却没有.另外,我做了一个console.log($scope.modal)来查看是否设置了我的变量,结果是:
ionic.Utils.inherit.child {focusFirstInput: true, unfocusOnHide: true, focusFirstDelay: 600, backdropClickToClose: false, hardwareBackButtonClose: false…}$el: JQLite[1]animation: "slide-in-up"backdropClickToClose: falseel: div.modal-backdropfocusFirstDelay: 600focusFirstInput: truehardwareBackButtonClose: falsemodalEl: ion-modal-view.modalscope: ChildScopeunfocusOnHide: trueviewType: "modal"__proto__: ionic.Utils.inherit.Surrogate
谁能帮我这个忙吗?提前致谢.
解决方法:
该错误意味着未创建$scope.modal-您对fromTemplateUrl的调用不正确.第二个参数是模式选项,您正在传递回调.
该文档提供了一个good example.
在您的情况下,对fromTemplateUrl的调用应如下所示:
$ionicModal.fromTemplateUrl('templates/loginModal.html', {
scope: $scope,
animation: 'slide-in-up',
backdropClickToClose: false,
hardwareBackButtonClose: false,
focusFirstInput: true
}).then(function(modal) {
$scope.modal = modal;
console.log($scope.modal);
});
标签:angularjs,ionic-framework,javascript,android 来源: https://codeday.me/bug/20191120/2046466.html