2016-05-17 175 views
0

我是新來的角,我需要調用另一個角度js.jow中的控制器的功能?請幫我在此先感謝 從另一個控制器調用另一個控制器的功能

<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; 
          } 
         } 

        }); 
    }); 

我是新來的,所以請我吧與格式

  1. HTML文件。

+0

在他們的角度是指導和控制器之間的綁定功能的方式,但我不知道控制器和控制器的....但爲什麼你需要從另一個控制器調用一個控制器函數......背後的主要目的是什麼? – pritesh

回答

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. 
     }); 
相關問題