我有以下的div設置另一個控制器範圍的變量,而無需使用angular.element(Angularjs)
<div ng-controller="MyController as MC" id="div1">
<a href="#" id="1" ng-init="MC.EntityId = 1 , MC.EntityType = 57" ng-click="MC.LoadFiles(MC.EntityId, MC.EntityType)" title="Upload">Upload </a>
</div>
我想在這裏顯示ENTITYID和的EntityType我在DIV1
<div ng-controller="MyController as MC" id="div2">
EntityId = {{MC.EntityId}}, EntityType = {{MC.EntityType}}
</div>
如何已經設置我爲LoadFiles函數中的div2設置EntityId和EntityType,而不使用angular.element。
app.controller('MyController', function() {
this.EntityId = 0;
this.EntityType = 0;
this.LoadFiles = function (id, type){
this.EntityId = id;
this.EntityType = type;
}
});
相關,可能重複[這是什麼在AngularJS控制器之間溝通的正確方法(http://stackoverflow.com/questions/11252780/whats-the-correct-way-to-communicate -between-controllers-in-angularjs) –
爲什麼你說另一個控制器範圍?只有一個控制器 –