没有视图注释的Angular2组件 [英] Angular2 component without view annotation
问题描述
我希望能够使用Angular2在我的服务器呈现的页面(ASP.Net MVC6)上进行客户端数据绑定.
I would like to be able to use Angular2 to do client-side databinding on my server-rendered pages (ASP.Net MVC6).
是否可以在不添加@view模板的情况下执行此操作?与其内联定义或创建外部模板,不如使用app元素将服务器呈现的HTML块括起来.这就是我在Angular1中所做的,因为它允许我选择是在服务器端还是在客户端进行数据绑定.
Is it possible to do this without adding a @view template? Instead of defining it inline or creating an external template, I would like to enclose a block of server-rendered HTML with the app element. This was how I did it in Angular1, as it allows me to choose whether to databind on the server-side or on the client-side.
谢谢.
推荐答案
您可以执行类似的操作,这可能就是您想要的.举个例子:
You can do something similar, that is probably what you want. Take this example:
import {Component, View, bootstrap} from "angular2/angular2";
@Component({
selector: "app"
})
@View({
template: "<content></content>"
})
export class App {
public name: string;
constructor() {
this.name = "MyName";
}
}
bootstrap(App);
模板具有特殊内容
表示ngTransclude指令的<content></content>
.这将使您可以在app标签内添加内容:
The template has a special content
<content></content>
that represents the ngTransclude directive. This will allow you to add content inside the app tag:
<app>
<h1>Hello World</h1>
</app>
不幸的是,这仍然没有得到很好的记录和更改,因此很难说出实际的限制,甚至很难保持这种状态.
Unfortunately this is still poorly undocumented and changing so it's hard to tell about the actual limitations or even if this will remain like this.
致谢.
这篇关于没有视图注释的Angular2组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!