【问题标题】:AngularJS displaying as plain textAngularJS 显示为纯文本
【发布时间】: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


【解决方案1】:

您将模块定义为app

var app = angular.module('phonecatApp', ['ui.bootstrap']);

并在phonecatApp 模块上定义您的控制器。所以改成:

var phonecatApp = angular.module('phonecatApp', ['ui.bootstrap']);

【讨论】:

    【解决方案2】:

    模块检查一次的命名问题。替换为 phonecatApp

    【讨论】:

      【解决方案3】:

      我认为你在app2.js 中有错误。您应该将phonecatApp.controller 替换为app.controller。因为你已经声明了var app=...,所以你应该使用app.controller。希望它有效!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-18
        • 2012-01-31
        • 2013-05-19
        • 2013-01-25
        • 2015-07-06
        • 2021-09-28
        • 2021-05-20
        相关资源
        最近更新 更多