如果调用 .component() 则不会调用模块配置函数

module configuration function is not being called if the .component() is called

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

  1. module.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. 电影-list.component.js

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

有了这个,我根本没有看到配置功能正在运行。如果我删除第二个文件中的 module.component(),则配置函数成功命中。

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

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

没问题