0
我在寫一個控制器。該控制器必須與其他控制器通信。但我不知道它是否可行?如何在AngularJS中相互溝通控制器?
HTML:
<div data-ng-app="TestApp">
<div data-ng-controller="menuCtrl">
<ul>
<li> <a data-ng-click="Click()">
Menü1</a>
</li>
</ul>
</div>
<div data-ng-controller="pageCtrl">
<hr/>
<button data-ng-click="getText()">GetText</button>
<br/>
<strong data-ng-model="boldText"> {{boldText}}</strong>
</div>
JS:
var app = angular.module('TestApp', []);
app.controller('menuCtrl', function ($rootScope, $scope) {
$scope.Click = function() {
//???
};
})
.controller('pageCtrl', function ($rootScope, $scope) {
$scope.getText = function() {
$scope.boldText = 'tst';
};
});
我修好樣品上的jsfiddle:sample
可能重複(HTTP [什麼是在AngularJS控制器之間溝通的正確方法是什麼?]: //stackoverflow.com/questions/11252780/whats-the-correct-way-to-communicate-between-controllers-in-angularjs) – 2015-02-11 08:39:45