[Angular 2] 6. Binding (not .apply(), .digest())

function Clock() {
    var clock = this;
    clock.time = 0;
    clock.message = "This is the message";

    setInterval(function() {
        clock.time++;
    }, 1000);
}
Clock.annotations = [
    new angular.ComponentAnnotation({
      selector: 'clock'
    }),
    new angular.ViewAnnotation({
        template: '{{message}} {{time}}',
        directives: []
    })
];
document.addEventListener("DOMContentLoaded", function() {
    angular.bootstrap(Clock);
});

 

In Angular 2, bingind is not available in html, you can only do it from the view component, template or templateurl, not in your index.html. In index.html it would only has one bootstrap componenet, all the child componenet are build on that.

 

Another thing is in Angular 2 , there is no .apply(), .digest(). For example the code in setInterval(), in Angular 1.x, you need to call .$scope.apply(), but in version 2. You don't need to do that anymore.

posted @ 2015-08-18 16:49  Zhentiw  阅读(221)  评论(0)    收藏  举报