对话框窗口有一个单独的控制器ctrl2
和功能,如果我将它作为链添加到相同的ctrl它可以工作,但将其添加到另一个文件中,以便它可以在别处使用它抛出错误
ng:areq] Argument 'ctrl2' is not a function, got undefined
案例2中的错误是什么?
案例1:在同一档案中(工作正常)
file1.ctrl.js
(function () {
'use strict';
angular
.module('app.mydev.module1',[])
.controller('ctrl1', crtl1)
.controller('ctrl2', ctrl2);
/* @ngInject */
function ctrl1($scope, $mdDialog) {
var vm = this;
$scope.showAdvanced = function(ev) {
$mdDialog.show({
templateUrl: 'app/mydev/mypage.tmpl.html',
parent: angular.element(document.body),
controller: 'ctrl2',
controllerAs : 'vm',
targetEvent: ev,
clickOutsideToClose:true,
fullscreen: $scope.customFullscreen // Only for -xs, -sm breakpoints.
})
.then(function(answer) {
$scope.status = 'You said the information was "' + answer + '".';
}, function() {
$scope.status = 'You cancelled the dialog.';
});
};
}
/* @ngInject */
function ctrl2($scope, $mdDialog) {
var vm = this;
vm.user = {
email: '',
password: ''
};
}
})();
案例2:在单独的文件中(它抛出错误)
File1.ctrl.js
(function () {
'use strict';
angular
.module('app.mydev.module1',[])
.controller('ctrl1', crtl1);
/* @ngInject */
function ctrl1($scope, $mdDialog) {
var vm = this;
$scope.showAdvanced = function(ev) {
$mdDialog.show({
templateUrl: 'app/mydev/mypage.tmpl.html',
parent: angular.element(document.body),
controller: 'ctrl2',
controllerAs : 'vm',
targetEvent: ev,
clickOutsideToClose:true,
fullscreen: $scope.customFullscreen // Only for -xs, -sm breakpoints.
})
.then(function(answer) {
$scope.status = 'You said the information was "' + answer + '".';
}, function() {
$scope.status = 'You cancelled the dialog.';
});
};
}
})();
File2.ctrl.js
(function () {
'use strict';
angular
.module('app.mydev.module1',[])
.controller('ctrl2', ctrl2);
/* @ngInject */
function ctrl2($scope, $mdDialog) {
var vm = this;
vm.user = {
email: '',
password: ''
};
}
})();