简体   繁体   English

将控制器添加到主体时,AngularJS表达式停止工作

[英]AngularJS expressions stop working when adding controller to body

I've tried building a simple Todo List app using ionic framework , however I've experienced a problem. 我尝试使用ionic框架构建一个简单的Todo List应用程序,但是遇到了一个问题。
Whenever I add the ng-controller and ng-reapeat directives to my code, AngularJS expressions stop working. 每当我在代码中添加ng-controllerng-reapeat指令时,AngularJS表达式就会停止工作。
Here is my code: 这是我的代码:
index.html index.html

<!DOCTYPE html>
<html ng-app="starter">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
  </head>
  <body>

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">ToDo</h1>
      </ion-header-bar>
      <ion-content>
        <ion-list>
          <ion-item ng-repeat="todo in TodoList">{{todo.name}}</ion-item>
        </ion-list>
      </ion-content>
    </ion-pane>
  </body>
</html>

app.js app.js

var app = angular.module('ionicApp', ['ionic'])
app.controller('TodoCtrl', function($scope){
  $scope.TodoList = [
    {name: "Item 1"},
    {name: "Item 2"}
  ]
})

You are defining the core module of your app in app.js as: 您在app.js中将应用程序的核心模块定义为:

var app = angular.module('ionicApp', ['ionic'])

However, in your html, you're defining your app as: 但是,在html中,您将应用定义为:

<html ng-app="starter">

In your ng-app attribute, you're defining this app as an Angular app, and you're referencing a module which does not exist ( starter ). ng-app属性中,您将此应用定义为Angular应用,并且引用了一个不存在的模块( starter )。 You need to specify which Angular module to use, which in your app.js at the moment is ionicApp . 您需要指定要使用的Angular模块,目前在app.js中是ionicApp So try renaming starter to ionicApp , or the otherway around, as long as they have matching names. 因此,只要它们具有匹配的名称,请尝试将starter重命名为ionicApp ,反之亦然。

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

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