Angularjs ui-router not reaching child controller

前端 未结 1 1790
礼貌的吻别
礼貌的吻别 2020-11-27 08:26

I\'ve got a config function:

function config($stateProvider,$locationProvider) {
$locationProvider.html5Mode(true);
$stateProvider
    .state(\'projectsWs.ta         


        
1条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 08:51

    Absolute naming with UI-Router works a bit differntly then you've used it

    .state('projectsWs.tasks.detail', {
        url: "/:taskId",
        views: {
            "mainView@": {
                templateUrl: "/app/projects/templates/index.php"
            },
            // this won't work, because the part after @
            // must be state name
            "innerView@mainView": {
    
            // so we would need this to target root, index.html
            "innerView@": {
    
            // or this to target nested view inside of a parent
            "innerView": {
    
            // which is the same as this
            "innerView@projectsWs.tasks": {
    

    Check the:

    View Names - Relative vs. Absolute Names

    small cite:

    Behind the scenes, every view gets assigned an absolute name that follows a scheme of viewname@statename, where viewname is the name used in the view directive and state name is the state's absolute name, e.g. contact.item. You can also choose to write your view names in the absolute syntax.

    I created a working example here, and the states are like this

    $stateProvider
    .state('projectsWs', {
      template: '
    ' + '
    ', }) $stateProvider .state('projectsWs.tasks', { url: "/tasks", views: { "mainView": { //templateUrl: "/app/projects/templates/index.php" template: "
    main view tasks
    ", }, "innerView": { //templateUrl: "/app/projects/templates/tasks.php", template: "
    inner view tasks
    ", } } }) .state('projectsWs.tasks.detail', { url: "/:taskId", views: { "mainView@projectsWs": { //templateUrl: "/app/projects/templates/index.php" template: "
    main view task {{$stateParams | json }}
    ", }, "innerView@projectsWs": { //templateUrl: "/app/projects/templates/tasks.php", template: "
    inner view task {{$stateParams | json }}
    ", } } });

    What we can see is, that the grand parent projectsWs is injecting into index.html (root)

    some template, with two named anchors:

    template: '
    ' + '
    ',

    this are then used in list and detail states, with relative resp absolute names

    Check it here in action

    0 讨论(0)
提交回复
热议问题