如何在Angular2 Javascript中添加子组件(没有typescript)
How to add a child component in Angular2 Javascript (no typescript)
我有一个在Angular2 RC5中运行的hello world程序,没有typescript。第一个组件加载时没有错误,但我无法加载子组件。我没有得到任何错误——子组件内容只是没有呈现/显示。
我也不知道如何把它放在plunkr或codependency上,因为似乎没有rpc的cdn。'npm install'的版本在https://github.com/dolthead/ng2js.
// app.module.js
(function (app) {
app.AppModule =
ng.core.NgModule({
imports: [ng.platformBrowser.BrowserModule],
declarations: [app.AppComponent, app.InputListComponent],
bootstrap: [app.AppComponent]
})
.Class({
constructor: function () {
}
});
document.addEventListener('DOMContentLoaded', function () {
ng.platformBrowserDynamic
.platformBrowserDynamic()
.bootstrapModule(app.AppModule);
});
})(window.app || (window.app = {}));
// app.component.js
(function (app) {
app.AppComponent =
ng.core.Component({
selector: 'my-app',
templateUrl: 'app/app.component.html',
imports: [app.InputListComponent],
directives: [
app.InputListComponent, // child component
ng.common.FORM_DIRECTIVES] // for ngModel
})
.Class({
constructor: function () {
}
});
})(window.app || (window.app = {}));
// input-list.component.js - the child component
(function (app) {
app.InputListComponent =
ng.core.Component({
selector: 'input-list',
templateUrl: 'app/input-list.component.html'
})
.Class({
constructor: function () {
console.log('input-list constructor');
var self = this;
self.status = '';
self.statusList = [];
self.addStatus = function() {
self.statusList.push(this.status);
this.status = '';
}
}
});
})(window.app || (window.app = {}));
这是我如何让ng-model与RC6 (js, no ts)一起工作的。将forms模块添加到index.html:
<script src="node_modules/@angular/forms/bundles/forms.umd.js"></script>
并在NgModule元数据中导入FormsModule:
// app.module.js
(function (app) {
app.AppModule =
ng.core.NgModule({
imports: [
ng.platformBrowser.BrowserModule,
ng.forms.FormsModule
],
declarations: [
app.AppComponent,
app.InputListComponent
],
providers: [],
bootstrap: [app.AppComponent]
})
.Class({
constructor: function AppModule() {
}
});
document.addEventListener('DOMContentLoaded', function () {
ng.platformBrowserDynamic
.platformBrowserDynamic()
.bootstrapModule(app.AppModule);
});
})(window.app || (window.app = {}));
// app.component.js
(function (app) {
app.AppComponent =
ng.core.Component({
selector: 'my-app',
templateUrl: 'app/app.component.html',
imports: [app.InputListComponent]
})
.Class({
constructor: function () {
}
});
})(window.app || (window.app = {}));
// input-list.component.js - the child component
(function (app) {
app.InputListComponent =
ng.core.Component({
selector: 'input-list',
templateUrl: 'app/input-list.component.html'
})
.Class({
constructor: function () {
console.log('input-list constructor');
var self = this;
self.status = '';
self.statusList = [];
self.addStatus = function() {
self.statusList.push(this.status);
this.status = '';
}
}
});
})(window.app || (window.app = {}));
相关文章:
- 调度没有'无法立即更新组件
- 有没有一个Nodejs库可以序列化和反序列化命名组件的路径(比如URL路径名)
- React AppendChild组件没有'不起作用
- Angular 2,在没有直接关系的两个组件之间共享一个对象
- 为什么 ReactJS 没有捕获子组件的渲染异常
- AJAX 请求没有在我的 React 组件中设置 this.state.data
- Firefox附加组件:cfx-run运行良好,cfx-xpi运行良好,但附加组件没有任何作用
- 提供者组件没有't重新渲染
- 为什么我的VueJs组件没有显示在前端
- Vue组件没有正确更新
- 根路由组件没有连接到redux
- 使用仅浏览器应用时,firebase-element聚合物组件没有响应
- 我如何让Babel与transform-react-jsx正确转换组件没有模块.导出(供ACE编辑器使用)
- 降级的Angular2组件没有在angular 1中渲染
- 如何在Angular2 Javascript中添加子组件(没有typescript)
- Angular2 rc5>组件没有被加载
- 为什么我的组件没有得到它的父数据,除非在activejs中指定
- NS_NOINTERFACE:组件没有请求的接口[nsIDOMLocation.reload]
- 为什么我的 React 组件没有在 setState() 上重新渲染
- 为什么我的react组件没有使用状态更新进行更新