簡體   English   中英

AngularJS顯示為純文本

[英]AngularJS displaying as plain text

我目前無法顯示有角度的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.'
      }
    ];
});

您將模塊定義為app

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

並在phonecatApp模塊上定義您的控制器。 因此更改為:

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

我認為您在app2.js有錯誤。 您應該用phonecatApp.controller替換app.controller 因為您已經聲明了var app=...所以您應該使用app.controller 希望它能起作用!

模塊檢查一次命名問題。 用phonecatApp替換

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM