自变量'PeopleController'不是函数,得到了未定义的IonicJS
Argument 'PeopleController' is not a function, got undefined IonicJS
- 使用IonicJS并呈现一些json细节
- 获取错误:"参数'PeopleController'不是函数,未定义"我查过文件了people_controller.js
(函数(){var app=角度模块('peopleController',[]);
app.controller('PeopleController',
function($scope, $http) {
var url = 'http://localhost:3000/api/people';
$http.get(url)
.success(function(people) {
$scope.people = people;
})
.error(function(data) {
console.log('server side error occurred.');
});
}
);
});
app.js:
angular.module('starter', ['ionic', 'peopleController'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
index.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></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="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content>
<ul class="list" ng-controller="PeopleController">
<li class="item" ng-repeat="person in people">
<h3>{{person.name}}</h3>
</li>
</ul>
</ion-content>
</ion-pane>
<script src="../js/controllers/people_controller.js"></script>
</body>
</html>
我做错了什么
在将PeopleController模块编译/插入应用程序之前,您正在注入该模块。检查JS文件的顺序。加载PeopleController.js,然后加载app.js
您需要从模块依赖项===>angular.module('starter', ['ionic'])
中删除peopleController
。
它是一个控制器,而不是一个模块。
编辑
更改app.controller('PeopleController',...)
CCD_ 4。
添加Angular文件和PeopleController.js文件以及
<!-- your app's js -->
<script src="angular/angular.min.js"></script>
<!-- ionic Dependencies ? -->
<script src="js/app.js"></script>
<script src="js/PeopleController.js"></script>
最终的问题是JS文件的序列,尝试在peopleController.JS之后加载app.JS文件,但一无所获。
在那之后,在加载peopleController.js之后立即加载app.js,它就像一个魅力
<script src="js/app.js"></script>
<script src="js/controllers/people_controller.js"></script>
整个项目现在:
index.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></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>
<script src="js/controllers/people_controller.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content>
<ul class="list" ng-controller="PeopleController">
<li class="item" ng-repeat="person in people">
<h3>{{person.name}}</h3>
</li>
</ul>
</ion-content>
</ion-pane>
</body>
</html>
app.js
angular.module('starter', ['ionic', 'peopleController'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
peopleController.js:
(function() {
var app = angular.module('peopleController', []);
app.controller('PeopleController',
function($scope, $http) {
var url = 'http://localhost:3000/api/people';
$http.get(url)
.success(function(people) {
$scope.people = people;
})
.error(function(data) {
console.log('server side error occurred.');
});
}
);
})();
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS指令出错-无法读取属性'编译'的未定义
- 这.SOMETHING 总是返回未定义的 - extjs
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- Wordpress中带有JQuery Accordion的未定义匿名函数
- 自变量'PeopleController'不是函数,得到了未定义的IonicJS