Angularjs 如何通过typescript绑定同级中的数据
绑定这两个同级child1.controller.ts中的值和 child2.controller.ts child1.controller.ts 我想使用child2.controller->newValue来设置 child1.控制器->comingValueAngularjs 如何通过typescript绑定同级中的数据,angularjs,typescript,Angularjs,Typescript,绑定这两个同级child1.controller.ts中的值和 child2.controller.ts child1.controller.ts 我想使用child2.controller->newValue来设置 child1.控制器->comingValue 您可以使用双向绑定 <child1-tab my-model="vm.model"></child1-tab> <child2-tab my-model="vm.model"></child2
您可以使用双向绑定
<child1-tab my-model="vm.model"></child1-tab>
<child2-tab my-model="vm.model"></child2-tab>
或者你可以使用
另一篇关于angular的文章。是的,我是通过$rootScope.$emit和$rootScope.$on完成的。您简要描述了双向绑定my model=“vm model”。它的工作原理以及我如何使用它来共享数据。谢谢
module app.parent{
'use strict';
class ParentController {
static $inject = ["$scope"];
constructor(public $scope)
{
scope.status = "Parent Controller";
}
}
}
/*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-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);
}
<child1-tab my-model="vm.model"></child1-tab>
<child2-tab my-model="vm.model"></child2-tab>