AngularJS1.5+組件不支持Watcher,其工作是什么?我一直在將我的自定義指令升級到新的組件體系結構..我讀過組件不支持觀察者。這是對的嗎?如果是,如何檢測對象上的更改?對于一個基本示例,我有自定義組件。myBox它有一個在游戲上綁定的子組件游戲。如果游戲組件中存在更改游戲,如何在myBox中顯示警告消息?據(jù)我所知,有rxJS方法,可以純粹在角度上這樣做嗎?我的JSFiddleJavaScriptvar app = angular.module('myApp', []);app.controller('mainCtrl', function($scope) {
$scope.name = "Tony Danza";});app.component("myBox", {
bindings: {},
controller: function($element) {
var myBox = this;
myBox.game = 'World Of warcraft';
//IF myBox.game changes, show alert message 'NAME CHANGE'
},
controllerAs: 'myBox',
templateUrl: "/template",
transclude: true})app.component("game", {
bindings: {game:'='},
controller: function($element) {
var game = this;
},
controllerAs: 'game',
templateUrl: "/template2"})HTML<div ng-app="myApp" ng-controller="mainCtrl">
<script type="text/ng-template" id="/template">
<div style='width:40%;border:2px solid black;background-color:yellow'>
Your Favourite game is: {{myBox.game}}
<game game='myBox.game'></game>
</div>
</script>
<script type="text/ng-template" id="/template2">
<div>
</br>
Change Game
<textarea ng-model='game.game'></textarea>
</div>
</script>
Hi {{name}} <my-box>
</my-box></div><!--end app-->
3 回答

慕斯王
TA貢獻1864條經(jīng)驗 獲得超2個贊
.component
component
selector
directive
.directive
link/compile
.component
$onChanges
/$doCheck
$ONChanges(ChangesObj)
-每當更新綁定時調用。ChangesObj是一個哈希,其鍵是綁定屬性的名稱。 $doCheck()
-在綁定更改時調用摘要周期的每一個回合。提供一個檢測更改并對其采取行動的機會。
- 3 回答
- 0 關注
- 628 瀏覽
添加回答
舉報
0/150
提交
取消