javascript - 当我尝试在 Ionic 中使用列表时,为什么会出现此 JavaScript 错误?

标签 javascript html css list ionic-framework

每次我尝试在我的应用程序中使用列表时它都不起作用,我打开了开发工具并且由于某种原因我收到以下错误,我是这些语言的新手所以非常感谢帮助。我尝试声明一个 var any 通过函数传递它,因为这就是我认为错误告诉我要做的,但那没有用。

HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>calorific</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 ng-app="calorific" ng-controller="calCtrl">
<ion-pane>

  <ion-content>
  <p></p>
  <div class="card">
       <div class="item item-text-wrap">                                          
          This is a basic Card which contains an item that has wrapping text.
          </div>
        </div>
    <ion-list>
        <ion-item ng-repeat="items in item"{{items.name}}> </ion-item>
    </ion-list>
  </ion-content>
</ion-pane>
</body>
</html>

JS:

 angular.module('calorific', ['ionic'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar   above the keyboard
// for form inputs)
 if(window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
 }
 if(window.StatusBar) {
  StatusBar.styleDefault();
 }
 });
 })

app.controller("calCtrl", function($scope) {
$scope.items= [
    {name: 'apple'},
    {name: 'banana'},
    {name: 'banana'},
    {name: 'banana'}
    ]
});

错误:

GET http://localhost:8100/css/style.css 
app.js:17 Uncaught ReferenceError: app is not defined
ionic.bundle.js:19526 Error: [ng:areq] Argument 'calCtrl' is not a function,  got undefined
http://errors.angularjs.org/1.3.13/ng/areq?    p0=calCtrl&p1=not%20a%20function%2C%20got%20undefined
at REGEX_STRING_REGEXP (ionic.bundle.js:7982)
at assertArg (ionic.bundle.js:9499)
at assertArgFn (ionic.bundle.js:9509)
at ionic.bundle.js:16350
at ionic.bundle.js:15518
at forEach (ionic.bundle.js:8250)
at nodeLinkFn (ionic.bundle.js:15505)
at compositeLinkFn (ionic.bundle.js:14997)
at publicLinkFn (ionic.bundle.js:14876)
at ionic.bundle.js:9369

最佳答案

在这一行你指定了app

app.controller("calCtrl", function($scope) {

但它没有在任何地方定义。

要么删除那个app,它会像:

angular.module('calorific', ['ionic'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar   above the keyboard
// for form inputs)
 if(window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
 }
 if(window.StatusBar) {
  StatusBar.styleDefault();
 }
 });
 })

.controller("calCtrl", function($scope) {
$scope.items= [
    {name: 'apple'},
    {name: 'banana'},
    {name: 'banana'},
    {name: 'banana'}
    ]
});

否则,使用如下:

 angular.module('calorific').controller("calCtrl", function($scope) {

关于javascript - 当我尝试在 Ionic 中使用列表时,为什么会出现此 JavaScript 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29474121/

相关文章:

php - 帐户信息格式问题

javascript - AngularJS 广播

javascript - 将下拉列表转换为文本框?

javascript - 检查输入是否为空或有文本而不是数字

javascript - 我如何在 JavaScript 中处理货币?

javascript - 如何在 Javascript 中格式化剪贴板数据,以便在粘贴到 MS Word 时创建软换行符?

html - 如何让文本出现在 <div> 内的文本之上

java - 自定义光标行为

javascript - 编程定时器

javascript - jQuery 如何刷新附加的 div 的特征?