2016-03-04 70 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' 
});