2016-03-04 24 views

回答

3

當你的代碼會在1.5釋放候選人都工作得很好,用於訪問組件模板控制器的命名約定在最終版本中被改變。現在默認爲$ctrl

app.component('exampleComponentTest', { 
    bindings: { 
     title: '=' 
    }, 
    template: '<h2>Title: {{$ctrl.title}}</h2>', 
    controller: function() { 

    } 
}); 
1

默認情況下,視圖中綁定的控制器名稱爲$ctrl

所以,如果你想要的工作,你應該有下面的模板:

template: '<h2>Title: {{$ctrl.title}}</h2>' 

如果你想使用exampleComponentTest,您必須在您的組件添加屬性controllerAs

app.component('exampleComponentTest', { 
    bindings: { 
     title: '=' 
    }, 
    template: '<h2>Title: {{exampleComponentTest.title}}</h2>', 
    controller: function() { 

    }, 
    controllerAs: 'exampleComponentTest' 
});