常规 ES5 中的 ng-model (Angular 2.0)
ng-model in regular ES5 (Angular 2.0)
我正在玩 Angular 2.0,但我在设置链接到 $scope 变量的输入元素时遇到了问题,就像我在 [ 中所做的那样=29=]1.x。我可以找到 typescript 的文档,但找不到 regular ES5.
的文档
在我下面的示例中,'myName' 显示在组件定义中,但未链接到输入。
function DisplayComponent() {
this.myName = "Jim";
}
DisplayComponent.annotations = [
new angular.ComponentAnnotation({
selector: "display"
}),
new angular.ViewAnnotation({
template:
'<input [(ng-model)]="myName" type="text">' +
'<p>name: {{ myName }}</p>'
})
];
document.addEventListener('DOMContentLoaded', function() {
angular.bootstrap(DisplayComponent);
});
您只需将 directives : [angular.formDirectives]
添加到您的 ViewAnnotation
,但它失败了,我不确定为什么。
这是你的 fiddle 和 angular2 alpha26
我让它与 alpha35 一起工作,这是迄今为止的最后一个版本。其中有一些变化:
- formDirectives 已重命名为 FORM_DIRECTIVES
- ComponentAnnotation 已重命名为 ComponentMetadata
- ViewAnnotation 已重命名为 ViewMetadata
- 全局
angular
现在是 ng
(不确定在哪个版本中更改)
这是使用 alpha35 的 fiddle:http://jsfiddle.net/ocscbk2u/
您使用的版本太旧。我建议您坚持使用最新版本,直到发布稳定版本。
我正在玩 Angular 2.0,但我在设置链接到 $scope 变量的输入元素时遇到了问题,就像我在 [ 中所做的那样=29=]1.x。我可以找到 typescript 的文档,但找不到 regular ES5.
的文档在我下面的示例中,'myName' 显示在组件定义中,但未链接到输入。
function DisplayComponent() {
this.myName = "Jim";
}
DisplayComponent.annotations = [
new angular.ComponentAnnotation({
selector: "display"
}),
new angular.ViewAnnotation({
template:
'<input [(ng-model)]="myName" type="text">' +
'<p>name: {{ myName }}</p>'
})
];
document.addEventListener('DOMContentLoaded', function() {
angular.bootstrap(DisplayComponent);
});
您只需将 directives : [angular.formDirectives]
添加到您的 ViewAnnotation
,但它失败了,我不确定为什么。
这是你的 fiddle 和 angular2 alpha26
我让它与 alpha35 一起工作,这是迄今为止的最后一个版本。其中有一些变化:
- formDirectives 已重命名为 FORM_DIRECTIVES
- ComponentAnnotation 已重命名为 ComponentMetadata
- ViewAnnotation 已重命名为 ViewMetadata
- 全局
angular
现在是ng
(不确定在哪个版本中更改)
这是使用 alpha35 的 fiddle:http://jsfiddle.net/ocscbk2u/
您使用的版本太旧。我建议您坚持使用最新版本,直到发布稳定版本。