【问题标题】:Beginner Angular JS app, interpolation not working初学者 Angular JS 应用程序,插值不起作用
【发布时间】:2016-11-17 10:38:38
【问题描述】:

我刚开始使用 Angular JS(版本 1),但无法正确运行插值。我已经用已解决的版本检查了它,对我来说看起来不错。我什至在控制器中放置了一个 console.log 并且它不打印任何东西。请帮忙。

index.html

<!doctype html>
<html lang="en" np-app="LunchCheck">
  <head>
    <meta charset="utf-8">
    <script src="angular.min.js"></script>
    <script src="app.js"></script>
    <title>Lunch Checker</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles/bootstrap.min.css">
    <style>
      .message { font-size: 1.3em; font-weight: bold; }
    </style>
  </head>
  <body>
      <div class="container" ng-controller="LunchCheckController">
       <h1>Lunch Checker</h1>
       <div class="form-group">
           <input id="lunch-menu" type="text"
           placeholder="list comma separated dishes you usually have for lunch"
           class="form-control" ng-model="food">
           Content is: {{food}}
       </div>
     </div>
  </body>
</html>

app.js

(function(){
  'use strict';

  angular.module('LunchCheck', [])

  .controller('LunchCheckController', LunchCheckController);

  LunchCheckController.$inject = ['$scope'];

  function LunchCheckController($scope){
    console.log("In controller");
    $scope.food = 'Enter something';
  }

})();

【问题讨论】:

  • 你写的是 np-app="LunchCheck" 而不是 ng-app

标签: javascript angularjs view controller


【解决方案1】:

用 ng-app 替换 np-app 就可以了

【讨论】:

    【解决方案2】:

    你写的是 np-app 而不是 ng-app

    &lt;html lang="en" np-app="LunchCheck"&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多