绑定这些两个兄弟姐妹中的值child1.controller.ts和 child2.controller.ts
/*
file :
index.html
|_app.ts
|_app.confing.ts (routing with parent.html and invoke parent controller)
|
|_parent.controller.ts
parent.html
|__ (invoke child1 Directive)
| |_child1.contoller.ts
| |_child1.html
|
|__(invoce child2 Directive)
|_child2.contoller.ts
|_child2.html
parent.html
<child1-tab></child1-tab>
<child2-tab></child2-tab>
*/
parent.controller.ts
module app.parent{
'use strict';
class ParentController {
static $inject = ["$scope"];
constructor(public $scope)
{
scope.status = "Parent Controller";
}
}
}
child1.controller.ts
/*child1-tab-Controller*/
module app.child1{
class child2Controller {
comingValue :string;
static $inject = ["$scope"];
constructor(public $scope){
this.comingValue = ""; //<= (I want to update it via child2.controller)
}
}
angular.module('myApp')
.controller('child1Controller', child1Controller);
}
child2.controller.ts
/*child2-tab-Controller*/
module app.child1{
class child2Controller {
newValue:string;
static $inject = ["$scope"];
constructor(public $scope){
this.newValue = "Send It to Child1"; //(newValue be send to child1Controller and set to the comingValue field in child1Controller)
}
}
angular.module('myApp')
.controller('child2Controller', child2Controller);
}
我想要使用child2.controller-&gt; newValue来设置 child1.controller-&GT; comingValue
答案 0 :(得分:1)
您可以使用双向绑定
<child1-tab my-model="vm.model"></child1-tab>
<child2-tab my-model="vm.model"></child2-tab>
或者您可以使用angular event system
另一篇关于角度为communication between directives的文章。