Angular-Ui-Router, nested named views - what am I doing wrong?

前端 未结 2 1310
执念已碎
执念已碎 2021-02-06 17:33

I\'m trying to implement a very simple example using nested named views using ui-router, and I can\'t get it to work. If anyone could look at this jsFiddle - http://jsfiddle.ne

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 17:46

    two issues in above code:

    1. As kju suggested abstract: true,

      An abstract state will never be directly activated, but can provide inherited properties to its common children states.

    2. add url: "" in test.sub state

      Using an empty url means that this child state will become active when its parent's url is navigated to.

    3. Don't manual transition to "test"

    See code below:

    angular.module('myApp', ['ui.state'])
    .config(['$stateProvider', '$routeProvider',  
        function ($stateProvider, $routeProvider) {
            $stateProvider
                .state('test', {
                    abstract: true,
                    url: '',
                    views: {
                        'main': {
                             template:  '

    Hello!!!

    ' + '
    ' + '
    ' } } }) .state('test.subs', { url: '', views: { 'view1': { template: "Im View1" }, 'view2': { template: "Im View2" } } }); }]) .run(['$rootScope', '$state', '$stateParams', function ($rootScope, $state, $stateParams) { $rootScope.$state = $state; $rootScope.$stateParams = $stateParams; // $state.transitionTo('test'); }]);

提交回复
热议问题