angular.js - 用requireJS模塊angularjs代碼時(shí)遇到一些問題
問題描述
原本的angularjs項(xiàng)目是可用的,但是在用requireJS時(shí)出錯(cuò)了。出錯(cuò)的是app.js原本的angularjs代碼中的app.js代碼是
angular.module(’todomvc’, [’ngRoute’, ’ngResource’]) .config(function ($routeProvider) {’use strict’;var routeConfig = { controller: ’TodoCtrl’, templateUrl: ’todomvc-index.html’, resolve: {store: function (todoStorage) { // Get the correct module (API or localStorage). return todoStorage.then(function (module) {module.get(); // Fetch the todo records in the background.return module; });} }};$routeProvider .when(’/’, routeConfig) .when(’/:status’, routeConfig) .otherwise({redirectTo: ’/’ }); });
用了requirejs后main.js
(function () { require.config({paths: { ’angular’: ’../node_modules/angular/angular’, ’angular-route’: ’../node_modules/angular-route/angular-route’, ’angular-resource’: ’../node_modules/angular-resource/angular-resource’},shim: { ’angular’: {exports: ’angular’ }, ’angular-route’: {deps: [’angular’],exports: ’angular-route’ }, ’angular-resource’: {deps: [’angular’],exports: ’angular-resource’ }},deps: [’bootstrap’] })})()
app.js
(function () { define([’angular’,’angular-route’,’angular-resource’],function (angular){var moduleName = ’myAppModule’;angular.module(moduleName, [’angular-route’,’angular-resource’]) .config(function ($routeProvider) {’use strict’;var routeConfig = { controller: ’TodoCtrl’, templateUrl: ’todomvc-index.html’, resolve: {store: function (todoStorage) { // Get the correct module (API or localStorage). return todoStorage.then(function (module) {module.get(); // Fetch the todo records in the background.return module; });} }};$routeProvider .when(’/’, routeConfig) .when(’/:status’, routeConfig) .otherwise({redirectTo: ’/’ }); }); return moduleName; })})()
瀏覽器報(bào)錯(cuò)注入出錯(cuò)了。。。接觸requirejs不久,有沒有大神教教該怎么改。
問題解答
回答1:問題顯然在這里:
angular.module(moduleName, [’angular-route’,’angular-resource’])
你的依賴還是應(yīng)該寫[’ngRoute’, ’ngResource’]。
回答2:搞不懂,ng都做了DI了為啥還要另外用個(gè)loader?
相關(guān)文章:
1. 致命錯(cuò)誤: Class ’appfacadeTest’ not found2. android - Apk 中找不到r類文件3. npm install -g browser-sync這個(gè)之后出錯(cuò) 還有人嗎 我都感覺沒人回答問題了4. javascript - 小程序跳轉(zhuǎn)失敗?5. dockerfile - 為什么docker容器啟動(dòng)不了?6. python - 數(shù)據(jù)無法插入到mysql表里7. java - Oracle如何獲取去重結(jié)果集中某一條數(shù)據(jù)的下一條數(shù)據(jù)8. javascript - 求正則表達(dá)式的寫法9. mysql set類型字段問題10. mysql scripts提示 /usr/bin/perl: bad interpreter
