【问题标题】:module configuration function is not being called if the .component() is called如果调用 .component() 则不会调用模块配置函数
【发布时间】:2018-07-18 16:21:54
【问题描述】:

我的 Angular 应用中有两个文件,如下所示:

  1. 模块.js

    (function () {
    
    "use strict";
    
    var module = angular.module("psMovies", ["ngRoute"]);
    
    module.config(["$routeProvider", function ($routeProvider) {
    
    $routeProvider
        .when("/list", { template: "<movie-list></movie-list>" })
        .when("/about", { template: "<app-about></app-about>" });
    }]);
    
    })();
    
  2. 电影列表.component.js

    (function () {
    
    var module = angular.module("psMovies", ["ngRoute"]);
    
    module.component("movieList", {
        template: "List goes here..."
    });
    
    })();
    

有了这个,我根本没有看到配置功能正在发挥作用。如果我在第二个文件中删除module.component(),则配置功能成功。

谁能解释一下为什么.component()会阻塞.config()内部的函数执行,我该如何解决?

【问题讨论】:

    标签: javascript angularjs angular-components


    【解决方案1】:

    在文件module.js中,你已经注入了ngRoute 所以你只需要在第二个文件中调用var module = angular.module("psMovies");module.component()没有问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-29
      • 1970-01-01
      • 2017-11-23
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      相关资源
      最近更新 更多