当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - In-Module Routing in AngularJS

问题描述:

I have a dashboard where x modules are integrated.

Means It looks like:

<div ng-controller="ACtrl"></div>

<div ng-controller="BCtrl"></div>

<div ng-controller="ACtrl"></div>

<div ng-controller="BCtrl"></div>

I do not use ng-app in my html and I bootstrap all angular modules manually.

The problem is that some modules can have multiple pages.

So I need a way to navigate / route somehow in my module-scope without changing the url. ( because this would trigger a page-switch in the other modules of same type too -> a module of type XY can be embedded in the html page x-times )

I found that angular-ui-router can handle routing without changing the url but in my tests, it always changed the url!

My test code:

 function Config($stateProvider, $urlRouterProvider) {

$stateProvider

.state('prepaid', {

url: '/prepaid',

template: '<ui-view/>',

abstract: true

})

.state('prepaid.dashboard', {

url: '/dashboard',

template: '<div><h4>dashboard</h4> <a ui-sref="prepaid.crm">TO CRM</a> <a ui-sref="prepaid.login">TO LOGIN</a></div>'

})

.state('prepaid.crm', {

url: '/crm',

//templateUrl: '/app/crm/crm.html',

template: '<div><h4>CRM</h4> <a ui-sref="prepaid.dashboard">TO DASHBOARD</a> <a ui-sref="prepaid.login">TO LOGIN</a></div>'

//controller: 'CrmCtrl'

})

.state('prepaid.login', {

url: '/login',

template: '<div><h4>login</h4><a ui-sref="prepaid.crm">TO CRM</a><a ui-sref="prepaid.dashboard">TO DASHBOARD</a></div>'

});

$urlRouterProvider.otherwise('/prepaid/crm');

}

angular.module('ModuleA').config(Config);

Is it possible to route in a module without to change the url? (I dont even want the /prepaid url!)

分享给朋友:
您可能感兴趣的文章:
随机阅读: