Javascript Angular 1.6.4如何检测组件无绑定属性的更改

Javascript Angular 1.6.4如何检测组件无绑定属性的更改,javascript,angularjs,angularjs-1.6,Javascript,Angularjs,Angularjs 1.6,也许有人知道如何解决这个问题: angular.module('myApp') .component('myComponent', { controller: function () { this.prop1 = 1; }, templateUrl: 'template.html' } 所以$watch不能用于新版本$onChanges-不起作用,因为这是内部属性。有人能解决这个问题吗?谢谢你的帮助。试试这个 angular.module('app.co

也许有人知道如何解决这个问题:

angular.module('myApp')
.component('myComponent', {
    controller: function () {
        this.prop1 = 1;
    },
    templateUrl: 'template.html'
}
所以$watch不能用于新版本$onChanges-不起作用,因为这是内部属性。有人能解决这个问题吗?谢谢你的帮助。

试试这个

angular.module('app.components', [])
.component('changeHandler', {
  controller: function ChangeHandlerController() {
    $onChanges: function (changes) {
      if (changes.canChange) 
       this.performActionWithValueOf(changes.canChange);
    };
  },
  bindings: {
    canChange: '<'
  },
  templateUrl: 'change-handler.html'
});

这是一个完全不同的问题,在我的代码中,我试图避免任何绑定。$watch不适用于新版本-你的意思是什么?尝试在Angular 1.6组件的控制器中使用$watch如何在控制器类上定义自己的属性并使用setter检测更改?是的,这将起作用,但是我想避免在这个组件中绑定。我需要像$watchthis这样的东西。_scope.$watch=>{return this.items;},newVal,oldVal=>{//在这里做你必须做的事情};