【发布时间】:2016-07-04 06:37:11
【问题描述】:
我目前无法让 Angular JS 显示,我不确定我做错了什么,因为它只在我的浏览器中显示为纯文本并且没有从 app2.js 传递信息.
我已将所有依赖项正确放置在我的代码中列出的位置,所以我认为我的代码可能出错了?
我的代码如下。
<!DOCTYPE html>
<html ng-app="phonecatApp" lang="en">
<head>
<title></title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="PhoneCat">
<!-- AngularUI Styles -->
<link rel="stylesheet" href="Content/ui-bootstrap-csp.css" />
</head>
<p>Total number of phones: {{phones.length}}</p>
<body ng-controller="PhoneListController">
<ul>
<li ng-repeat="phone in phones">
<span>{{phone.name}}</span>
<p>{{phone.snippet}}</p>
</li>
</ul>
</body>
<script src="scripts/angular.js"></script>
<script src="scripts/angular-ui/ui-bootstrap-tpls.min.js"></script>
<script src="scripts/app2.js"></script>
</html>
app2.js
// Define the `phonecatApp` module
var app = angular.module('phonecatApp', ['ui.bootstrap']);
// Define the `PhoneListController` controller on the `phonecatApp` module
phonecatApp.controller('PhoneListController', function PhoneListController($scope) {
$scope.phones = [
{
name: 'Nexus S',
snippet: 'Fast just got faster with Nexus S.'
}, {
name: 'Motorola XOOM™ with Wi-Fi',
snippet: 'The Next, Next Generation tablet.'
}, {
name: 'MOTOROLA XOOM™',
snippet: 'The Next, Next Generation tablet.'
}
];
});
【问题讨论】:
-
你的脚本标签没有结束符,
-
任何控制台错误?
-
app2.js:5 Uncaught ReferenceError: phonecatApp is not defined
-
angular.js:13708 错误:[ng:areq] 参数“PhoneListController”不是函数,在 angular.js:68 at assertArg (angular.js:1885) 处未定义 errors.angularjs.org/1.5.7/ng/… assertArgFn (angular.js:1895) at $controller (angular.js:10210) at setupControllers (angular.js:9331) at nodeLinkFn (angular.js:9116) at compositeLinkFn (angular.js:8510) at compositeLinkFn (angular.js:8510) js:8513) 在 publicLinkFn (angular.js:8390) 在 angular.js:1756
标签: javascript angularjs parsing text