国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

angular.js - 已實(shí)作的angularjs專案用requirejs進(jìn)行模組化時(shí)遇到問(wèn)題
phpcn_u1582
phpcn_u1582 2017-05-15 16:58:28
0
1
620

其實(shí)就是對(duì)todoMVC專案用requirejs進(jìn)行模組化。原本的angularjs分別在controller、directive、service中分別定義了一個(gè)模組來(lái)代表這三者。
下面是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']);
            })
    })
})();

之後打開(kāi)網(wǎng)頁(yè)發(fā)現(xiàn)所有的js檔案都載入出來(lái)了,但是並不能實(shí)現(xiàn)效果。 。

是不是app.js不能這麼寫。沒(méi)怎麼用過(guò)requireJS/(ㄒoㄒ)/~~

貼一下我的檔案路徑

下面是我的main.js

(function  (win) {
    'use strict';

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

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

phpcn_u1582
phpcn_u1582

全部回覆(1)
巴扎黑

模組依賴注入錯(cuò)誤了,檢查下引用路徑

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板