AngularJS:从另一个组件的模板中呈现组件
我正在努力学习angularjs,努力让我的第二个组件“list”进行渲染。语法有问题吗?以下是HTML:AngularJS:从另一个组件的模板中呈现组件,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我正在努力学习angularjs,努力让我的第二个组件“list”进行渲染。语法有问题吗?以下是HTML: <!DOCTYPE html> <html> <head> <title>Hello World, AngularJS - ViralPatel.net</title> <script type="text/javascript" src="https://ajax.googleapis.co
<!DOCTYPE html>
<html>
<head>
<title>Hello World, AngularJS - ViralPatel.net</title>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
</head>
<body ng-app="myModule">
Write some text in textbox:
<input type="text" ng-model="sometext" />
<h1>Hello {{ sometext }}</h1>
<app></app>
<script src="App.js"></script>
<script src="List.js"></script>
</body>
</html>
下面是App.js
angular.module('myModule', [])
.component('app', {
template:
'<div>' +
'<h1>Hello from App.js</h1>' +
'<list></list>' +
'</div>'
})
下面是List.js,它不会呈现:
angular.module('myModule', [])
.component('list', {
template:
'<h1>Hello from List.js</h1>'
'<ul>' +
'<li>1</li>' +
'<li>2</li>' +
'</ul>'
})
这里的问题似乎是您两次声明myModule。 执行以下操作时,将在每个.js文件中重新声明该模块两次: 角度。模块'myModule',[] AngularJS中一个微妙的问题是,当您将[]作为第二个参数传递给angular.module时,在AngularJS中内部声明了一个新模块 尝试将List.js修改为此,看看这是否有帮助:
/* Remove the [] to prevent myModule from being re-defined.
We assume myModule has been defined during the execution of App.js,
which should happen before List.js is executed */
angular
.module('myModule')
.component('list', {
template:
'<h1>Hello from List.js</h1>'
'<ul>' +
'<li>1</li>' +
'<li>2</li>' +
'</ul>'
})
谢谢你的帮助,后来我注意到模板中缺少了一个+。所以现在在屏幕上呈现,但我确实在控制台中得到一个错误,显示uncaughterror:[$injector:nomod]。编辑:nevermind,修复了错误链接后的错误。谢谢