今天把用ionic做一个案例,和ionic示例项目差不多,只是用requirejs分离了controller,但是一直报错
Error: [ng:areq] Argument ‘AppCtrl’ is not a function, got undefined
define(function (require) { 'use strict'; var controllers = angular.module('starter.controllers', []); controllers.controller('appCtrl',require('controllers/appController')); controllers.controller('dashCtrl',require('controllers/dashController')); controllers.controller('gameCtrl',require('controllers/gameController')); controllers.controller('meCtrl',require('controllers/meController')); controllers.controller('infoCtrl',require('controllers/infoController')); controllers.controller('playListCtrl',require('controllers/playListController'));return controllers; });
经过一番折腾还是没能解决。后来我细分析,我的控制器叫appCtrl,错误信息中怎么是AppCtrl,我试着将名称首字母大写,卧槽,居然通过了
define(function (require) { 'use strict'; var controllers = angular.module('starter.controllers', []); controllers.controller('AppCtrl',require('controllers/appController')); controllers.controller('DashCtrl',require('controllers/dashController')); controllers.controller('GameCtrl',require('controllers/gameController')); controllers.controller('MeCtrl',require('controllers/meController')); controllers.controller('InfoCtrl',require('controllers/infoController')); controllers.controller('PlayListCtrl',require('controllers/playListController')); return controllers; });
再在网上搜,原来 ionic 的 ui-router 是大小写敏感,这里定义的控制器名要与路由中定义的控制器名大小写一致