javascript - How to use $scope.$watch on TypeScript -
i want watch element binding component. value may change(in component) because makes asynchronous call (promise). until in js use $scope.$watch
, when binding element change has callback , can continue value of element.
example of js:
$scope.$watch('myctrl.mylayout', function (newval, oldval) { console.log('layout is:'); console.log(_this.mylayout); }); angular.module('blocks.ui') .component('myform', { templateurl: 'app/blocks/ui/form.html', controller: myform, controlleras: 'myctrl', bindings: { mylayout: '=' } });
the question how implement same thing using "clean" typescript syntax (i know can inject $scope , implement $scope.$watch
on typescript in same way).
thanks.
the solution using typescript & set
private _mylayout:any; public mylayout() { return this._mylayout; } public set mylayout(newitem: any) { this._mylayout = newitem; console.log('layout is:'); console.log(this.mylayout); }
Comments
Post a Comment