警告:试图加载角度不止一次。 Angular + Ionic +需要JS

时间:2015-09-18 23:48:29

标签: javascript angularjs requirejs ionic

我正在使用离子来构建混合应用程序。在这个应用程序中,我决定将Require.js作为依赖加载器(可能不是最好的选择,但我以前习惯使用它,因为我有很多项目对我来说更容易为WebApps和应用程序)。

问题是在我的main.js中我一个接一个地需要角度和离子(ionic.bundle)和Ionic,因为它有自己的角度实现,即使它已经加载也试图加载Angular

它不是一个破坏性的东西,它只是一个日志,但我想了解如何使它消失并成为最佳方式。

这是我的main.js



require.config({
    paths: {
        "angular": "../bower_components/angular/angular.min",
        "ionic": "../bower_components/ionic/release/js/ionic.bundle.min",
        "angular-animate": "../bower_components/angular-animate/angular-animate.min",
        "angular-touch": "../bower_components/angular-touch/angular-touch.min",
        "angular-cookies": "../bower_components/angular-cookies/angular-cookies.min",
        "angular-aria": "../bower_components/angular-aria/angular-aria.min",
        "angular-material": "../bower_components/angular-material/angular-material.min",
        "angular-ui-router": "../bower_components/angular-ui-router/release/angular-ui-router.min",
        "angular-modal-service": "../bower_components/angular-modal-service/dst/angular-modal-service.min",
        text: "../bower_components/text/text",
        "angular-file-model": "../bower_components/angular-file-model/angular-file-model.min",
        "moment": "../bower_components/moment/min/moment.min",
        "angular-moment": "../bower_components/angular-moment/angular-moment.min",
        "moment-it": "../bower_components/moment/locale/it",
    },
    shim: {
        angular: {
            exports: "angular"
        },
        ionic: {
            deps: ["angular", "angular-aria", "angular-animate"],
            exports: "ionic"
        },
        "angular-ui-router": ["angular"],
        "angular-modal-service": ["angular"],
        "angular-file-model": ["angular"],
        "angular-cookies": ["angular"],
        "angular-moment" : [
            "angular",
            "moment",
        ],
        "moment-it": ["moment"],
        "angular-animate": ["angular"],
        "angular-aria": ["angular"],
        "angular-touch": ["angular"],
        "angular-material": ["angular", "angular-animate", "angular-aria"]

    }
});

require([
    "angular",
    "./dependencies",
    "./configs/configs",
    "./services/services",
    "./states/states",
    "./directives/directives",
    // "./dialogs/dialogs",
    "./toasts/toasts",
], function(angular) {
    "use strict";
    var modules = Array.prototype.slice.call(arguments, 1).map(function(module) {
        return module.name;
    });
    angular.module("app", modules);
    angular.bootstrap(document, ["app"]);
});




1 个答案:

答案 0 :(得分:0)

我决定用以下方式更改main.js:

我打电话给#34; angular" ionic.bundle.js。 不要忘记将离子作为角度依赖包括在内



require.config({
    paths: {
        //"angular": "../bower_components/angular/angular.min",
        "angular": "../bower_components/ionic/release/js/ionic.bundle.min",
        "angular-animate": "../bower_components/angular-animate/angular-animate.min",
        "angular-cookies": "../bower_components/angular-cookies/angular-cookies.min",
        "angular-aria": "../bower_components/angular-aria/angular-aria.min",
        "angular-material": "../bower_components/angular-material/angular-material.min",
        "angular-ui-router": "../bower_components/angular-ui-router/release/angular-ui-router.min",
        "angular-modal-service": "../bower_components/angular-modal-service/dst/angular-modal-service.min",
        text: "../bower_components/text/text",
        "angular-file-model": "../bower_components/angular-file-model/angular-file-model.min",
        "moment": "../bower_components/moment/min/moment.min",
        "angular-moment": "../bower_components/angular-moment/angular-moment.min",
        "moment-it": "../bower_components/moment/locale/it",
    },
    shim: {
        angular: {
            exports: "angular"
        },
        "angular-ui-router": ["angular"],
        "angular-modal-service": ["angular"],
        "angular-file-model": ["angular"],
        "angular-cookies": ["angular"],
        "angular-moment" : [
            "angular",
            "moment",
        ],
        "moment-it": ["moment"],
        "angular-animate": ["angular"],
        "angular-aria": ["angular"],
        "angular-material": ["angular", "angular-animate", "angular-aria"]

    }
});

require([
    "angular",
    "./dependencies",
    "./configs/configs",
    "./services/services",
    "./states/states",
    "./directives/directives",
    // "./dialogs/dialogs",
    "./toasts/toasts",
], function(angular) {
    "use strict";
    var modules = Array.prototype.slice.call(arguments, 1).map(function(module) {
        return module.name;
    });
    angular.module("app", modules.concat(["ionic"]));
    angular.bootstrap(document, ["app"]);
});