Angular 2 @View with template vs @Component with template
问题描述:
我希望有人能为我解决这个问题。我假设对此有一个简单的答案。但如果它出现在互联网上,我似乎无法找到它。请记住,我有一点经验,所以我很抱歉,如果我失去了一些明显的东西。Angular 2 @View with template vs @Component with template
我看到下面的实施例在那里为在角2.
//Example 1
@Component({
selector: 'my-app'
})
@View({
template : '<p></p>'
})
据我所知创建模板,上面的例子是相同的,因为这。
// Example 2
@Component({
selector: 'my-app',
template: '<p></p>'
})
根据这一https://angular.io/docs/ts/latest/api/core/View-decorator.html这@Directive v/s @Component in angular2
那么有没有什么好的理由来创建一个像第一个例子VS第二哪里@View
似乎通过@Component
被隐式设置使用模板“模板”?
答
我认为你应该看看这个问题:Angular 2.0. Difference @View @Component。
你的例1和例2实际上做同样的事情...
事实上,这是相同的,因为View
是可选的,但在未来,你就可以定义多个视图的相同部件。
希望它可以帮助你, 蒂埃里
谢谢。我不知道那个..我会看看。 –