简体   繁体   中英

Beginner Angular JS app, interpolation not working

I just started with Angular JS (version 1), and not been able to get the interpolation running correctly. I already checked it with solved versions, and looks fine to me. I even placed a console.log inside controller and its not printing anything. Please help.

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';
  }

})();

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

您编写的是np-app而不是ng-app

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM