我是角度新手,我需要在角度j的另一个控制器中调用函数。如果可能的话?请提前帮助我
<a> <i ng-click="open('sm')"></i> <span>test</span> </a> <div ng-controller="MapModuleController"> <scrip enter code here`t type="text/ng-template" id="myModalContent.html"> <div class="modal-body"> {{ items }} // not display anything </div> <div class="modal-footer"> <button class="btn btn-primary" type="button" ng-click="ok()">{{ 'generic_ok' | translate}}</button> </div> </script> </div>
2.Controller
app.controller('ModalInstanceCtrl', function ($scope, $uibModalInstance,items) {
$scope.items = items;
$scope.ok = function () {
$uibModalInstance.dismiss('cancel');
};
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
});
app.controller('MapModuleController', ['$scope','$uibModal',
'$rootScope',function ($scope, $uibModal, $rootScope, ) {
$scope.testFunction = function(){
// want to call this function on press of okay button
};
$scope.msg = 'done';
$scope.open = function () {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.msg;
}
}
});
});
我是新来的,请格式化我。
答案 0 :(得分:0)
您可以将一个控制器注入另一个控制器,如下所示:
'use strict';
reachApp.controller('dashboardController', ['$scope','$controller', function ($scope, $controller) {
var feedbackModel = $scope.$new();
$controller('feedbackController',{$scope : feedbackModel });
feedbackModel.getLatestMeetingRating(); //And call the method on the newScope.
});