angular.js - 已實(shí)現(xiàn)的angularjs項(xiàng)目用requirejs進(jìn)行模塊化時(shí)遇到問題
問題描述
其實(shí)就是對(duì)todoMVC項(xiàng)目用requirejs進(jìn)行模塊化。原本的angularjs是分別在controller、directive、service中分別定義了一個(gè)模塊來代表這三者。下面是directive:todoFocus.js
(function () { ’use strict’ angular.module(’todoFocus’,[]).directive(’todoFocus’,function ($timeout){return function (scope,element,attrs){ scope.$watch(attrs.todoFocus,function (newVal){if(newVal){ $timeout(function(){element[0].focus(); },0,false);} })} })})()
上面就是一個(gè)directive。之后在app.js中
(function () { ’use strict’; angular.module(’todomvc’, [’todoCtrl’, ’todoFocus’, ’todoStorage’]);})();
我用requirejs模塊化之后directive變成了這樣:
(function () { ’use strict’ define([’angular’],function (angular) {angular.module(’todoFocus’,[]).directive(’todoFocus’,function ($timeout){return function (scope,element,attrs){ scope.$watch(attrs.todoFocus,function (newVal){if(newVal){ $timeout(function(){element[0].focus(); },0,false);} })} })return ’todoFocus’; })})()
然后app.js變成了這樣:
(function () { ’use strict’; require([’angular’],function (angular) {require([ ’controllers/todoCtrl’, ’directives/todoFocus’, ’services/todoStorage’ ],function (todoCtrl,todoFocus,todoStorage) {angular.module(’todomvc’,[todoCtrl,todoFocus,todoStorage]);angular.bootstrap(document, [’todomvc’]); }) })})();
之后打開網(wǎng)頁發(fā)現(xiàn)所有的js文件都加載出來了,但是并不能實(shí)現(xiàn)效果。。
是不是app.js不能這么寫。沒怎么用過requireJS/(ㄒoㄒ)/~~
貼一下我的文件路徑
下面是我的main.js
(function (win) { ’use strict’; require.config({paths: { angular: ’../node_modules/angular/angular’},shim: { //專門用來配置不兼容的模塊 angular: { exports: ’angular’ //輸出變量名,表示這個(gè)模塊外部調(diào)用時(shí)的名稱 }},deps: [’app’] //deps數(shù)組,表示該模塊依賴app模塊,所以要先加載app模塊});})(window)
感覺我的路徑?jīng)]啥問題呀/(ㄒoㄒ)/~~
問題解答
回答1:模塊依賴注入錯(cuò)誤了,檢查下引用路徑
相關(guān)文章:
1. 在應(yīng)用配置文件 app.php 中找不到’route_check_cache’配置項(xiàng)2. html按鍵開關(guān)如何提交我想需要的值到數(shù)據(jù)庫3. HTML 5輸入框只能輸入漢字、字母、數(shù)字、標(biāo)點(diǎn)符號(hào)?正則如何寫?4. javascript - 請(qǐng)教如何獲取百度貼吧新增的兩個(gè)加密參數(shù)5. Android中能不能判斷一個(gè)數(shù)據(jù)庫是create來的,還是open來的?6. gvim - 誰有vim里CSS的Indent文件, 能縮進(jìn)@media里面的7. 跟著課件一模一樣的操作使用tp6,出現(xiàn)了錯(cuò)誤8. PHP類屬性聲明?9. javascript - 求助canvas繪制馬賽克的問題,老是取色不準(zhǔn)10. java - 安卓接入微信登錄,onCreate不會(huì)執(zhí)行
