初学者Angular JS app,插值不起作用

时间:2016-11-17 10:38:38

标签: javascript angularjs view controller

我刚开始使用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';
  }

})();

2 个答案:

答案 0 :(得分:0)

用ng-app替换np-app它会起作用

答案 1 :(得分:0)

您已经编写了np-app而不是ng-app

<html lang="en" np-app="LunchCheck">