今天把用ionic做一個案例,和ionic示例項目差不多,只是用requirejs分離了controller,但是一直報錯 Error: [ng:areq] Argument ‘AppCtrl’ is not a function, got undefined 經過一番折騰還是沒能解決。後來我細分析 ...
今天把用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 是大小寫敏感,這裡定義的控制器名要與路由中定義的控制器名大小寫一致