久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

angular.js - 已實現(xiàn)的angularjs項目用requirejs進(jìn)行模塊化時遇到問題

瀏覽:111日期:2024-10-06 16:17:14

問題描述

其實就是對todoMVC項目用requirejs進(jìn)行模塊化。原本的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’]); }) })})();

之后打開網(wǎng)頁發(fā)現(xiàn)所有的js文件都加載出來了,但是并不能實現(xiàn)效果。。angular.js - 已實現(xiàn)的angularjs項目用requirejs進(jìn)行模塊化時遇到問題

angular.js - 已實現(xiàn)的angularjs項目用requirejs進(jìn)行模塊化時遇到問題

是不是app.js不能這么寫。沒怎么用過requireJS/(ㄒoㄒ)/~~

貼一下我的文件路徑angular.js - 已實現(xiàn)的angularjs項目用requirejs進(jìn)行模塊化時遇到問題

下面是我的main.js

(function (win) { ’use strict’; require.config({paths: { angular: ’../node_modules/angular/angular’},shim: { //專門用來配置不兼容的模塊 angular: { exports: ’angular’ //輸出變量名,表示這個模塊外部調(diào)用時的名稱 }},deps: [’app’] //deps數(shù)組,表示該模塊依賴app模塊,所以要先加載app模塊});})(window)

感覺我的路徑?jīng)]啥問題呀/(ㄒoㄒ)/~~

問題解答

回答1:

模塊依賴注入錯誤了,檢查下引用路徑

相關(guān)文章:
主站蜘蛛池模板: 会理县| 宝应县| 富顺县| 清镇市| 乌兰浩特市| 隆安县| 繁昌县| 涞水县| 铁岭县| 枣强县| 察哈| 仁怀市| 左权县| 丽江市| 祁东县| 合肥市| 龙门县| 萝北县| 桂阳县| 关岭| 乌兰察布市| 亚东县| 柏乡县| 绥宁县| 西畴县| 班玛县| 清原| 平谷区| 容城县| 满洲里市| 华容县| 镇安县| 壤塘县| 黔西县| 会理县| 台州市| 盐城市| 榆林市| 柳江县| 海城市| 云南省|