为什么模块2会显示在模块1内?
我们有一个包含多个模块的角度应用程序。对于某些模块,我们希望使用组件路由器。我们不知道该组件将在哪个页面(url)上加载。
当前情况:在模块1内,正在显示模块2的模板。
所需的结果:具有相对于组件的路径,以便'... com / someUrlWhereModule1Lives#/ step2'加载模块1
的步骤2 '... com / someUrlWhereModule2Lives#/ step2'加载模块2的步骤2
module1.module.js
angular
.module('app.module1', ['ngComponentRouter'])
.value('$routerRootComponent', 'module1')
.component('module1', {
templateUrl: 'module1.overview.html',
$routeConfig: [
{path: '/', name: 'Overview', component: 'module1Step1', useAsDefault: true},
{path: '/step2', name: 'Overview', component: 'module1Step2'}
]
})
.component('module1Step1', {
bindings: { $router: '<' },
templateUrl: 'module1.step1.html'
})
.component('module1Step2', {
bindings: { $router: '<' },
templateUrl: 'module1.step2.html'
});
module2.module.js
angular
.module('app.module2', ['ngComponentRouter'])
.value('$routerRootComponent', 'module2')
.component('module2', {
templateUrl: 'module2.overview.html',
$routeConfig: [
{path: '/', name: 'Overview', component: 'module2Step1', useAsDefault: true},
{path: '/step2', name: 'Step2', component: 'module2Step2'}
]
})
.component('module2Step1', {
bindings: { $router: '<' },
templateUrl: 'module2.step1.html'
})
.component('module2Step2', {
bindings: { $router: '<' },
templateUrl: 'module2.step2.html'
});
如果需要更多信息,请告诉我。
由于您是将Angular应用程序用作单个传呼机,因此我做了某种变通方法,其中您的模块(例如,模块一)启动用于保存模块路由的$ routerRootComponent(例如,component-router-component)。$ routerRootComponent会启动另一个拥有其自己的$ routeConfig的组件(例如,module-one-overview)。
有关代码示例,请参见我的Plunker。
(对不起,我不得不将其缩写为URL以避开Stackoverflow功能,该功能在引用Plunker URL时需要代码)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句