带有RxJs的角度1.5分量的伪代码:
{{1}}
有什么方法可以避免使用带有$ evalAsync的$ scope来触发摘要?没有它,视图根本就不会更新 为什么?因为angular2上没有$ scope,我希望尽可能简单地进行迁移
答案 0 :(得分:5)
You can use angular1-async-filter. Take a look at this good article: http://cvuorinen.net/2016/05/using-rxjs-observables-with-angularjs-1/
Here is an example:
(function(angular) {
var myComponent = (function () {
function myComponent() {
this.template = "<div><br/> Time: {{ctrl.time | async:this}}</div>";
this.controllerAs = 'ctrl';
this.controller = "myController";
}
return myComponent;
}());
var myController = (function() {
function myController() {
this.time = Rx.Observable.interval(1000).take(50);
}
return myController;
}());
angular.module('myApp', ['asyncFilter']);
angular.module('myApp').component('myComponent', new myComponent());
angular.module('myApp').controller('myController', myController);
})(window.angular);
See it working on Plunker: https://plnkr.co/edit/80S3AG?p=preview