angular.js - 已實現的angularjs項目用requirejs進行模塊化時遇到問題
問題描述
其實就是對todoMVC項目用requirejs進行模塊化。原本的angularjs是分別在controller、directive、service中分別定義了一個模塊來代表這三者。下面是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);} })} })})()
上面就是一個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’]); }) })})();
之后打開網頁發現所有的js文件都加載出來了,但是并不能實現效果。。
是不是app.js不能這么寫。沒怎么用過requireJS/(ㄒoㄒ)/~~
貼一下我的文件路徑
下面是我的main.js
(function (win) { ’use strict’; require.config({paths: { angular: ’../node_modules/angular/angular’},shim: { //專門用來配置不兼容的模塊 angular: { exports: ’angular’ //輸出變量名,表示這個模塊外部調用時的名稱 }},deps: [’app’] //deps數組,表示該模塊依賴app模塊,所以要先加載app模塊});})(window)
感覺我的路徑沒啥問題呀/(ㄒoㄒ)/~~
問題解答
回答1:模塊依賴注入錯誤了,檢查下引用路徑
相關文章:
1. (python)關于如何做到按win+R再輸入文件文件名就可以運行?2. javascript - 按鈕鏈接到另一個網址 怎么通過百度統計計算按鈕的點擊數量3. Python處理Dict生成json4. mysql 獲取時間函數unix_timestamp 問題?5. java - Mybatis 數據庫多表關聯分頁的問題6. 急急急!!!求大神解答網站評論問題,有大神幫幫小弟嗎7. php - 生產環境下,給MySQL添加索引,修改表結構操作,如何才能讓線上業務不受影響?8. python2.7 - python 正則前瞻 后瞻 無法匹配到正確的內容9. mysql - Sql union 操作10. python - 請問這兩個地方是為什么呢?
