简体   繁体   English

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

[英]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. 我刚开始使用Angular JS(版本1),但无法正确执行插值。 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. 我什至将console.log放置在控制器内部,并且不打印任何内容。 Please help. 请帮忙。

index.html 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 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">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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