Angular wierdness routing with ui-routing

One more question guys :) If I left the urll pattern blank in my routing, the scope would be requested but the pattern would not be shown. But if I write it the same way as in the linked plunker project, it will make the links invisible :( but only for li> a elements ... also in the plunker I can't make it workable, don't know why ... anyone ? http://plnkr.co/edit/VKhhcSmepMTxBT7R5AuO

And here is ap.js itself for help

(function(){
    var portApp = angular.module('portApp', ['ui.router']);

    portApp.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
        $urlRouterProvider.otherwise('/home');
        $stateProvider
            .state('root', {
                url: '/home',
                abstract: true,
                templateUrl: 'views/listView.html',
                controller: 'ListController'
            })
            .state('home', {
                url: '/home',
                templateUrl: 'views/listView.html',
                controller: 'ListController'
            })
            .state('about', {
                url: '/about',
                templateUrl: 'views/resumeView.html'
            })
            .state('items', {
                url: '/items/:itemLink',
                templateUrl: 'views/itemView.html',    
                controller: 'ItemController'
            });
            $locationProvider.html5Mode(true);
    });

    portApp.factory("workFactory", function() {
        var works = [
        {
            Title: "Sprite",
            subTitle: "",
            Link: "sprite",
            Thumbnail: "img/portfolio02.png",
            Image: "img/ismont.png"
        },
        {
            Title: "Pepsi",
            subTitle: "Kristályvíz",
            Link: "pepsi",
            Thumbnail: "img/portfolio03.png",
            Image: "img/sanofimont.png"
        }
        ];
        return {
            list: function() {
                return works;
            },
            selected: function(detPath) {
                selected = works.filter(function(work) {
                    return work.Link == detPath;
                });
                return selected;
            }
        };
    });

    portApp.controller("ListController", ["$scope", "workFactory", 
        function($scope, workFactory) {
            $scope.allWorks = workFactory.list();
        }
    ]);

    portApp.controller("ItemController", ["$scope", "workFactory", "$stateParams",
        function($scope, workFactory, $stateParams) {
            var detPath = $stateParams.itemLink;
            //$scope.selectedWork = workFactory.selected(detPath);
            $scope.selectedWork = workFactory.selected(detPath)[0];
            alert($scope.selectedWork);
        }
    ]);

})();

      

+1


source to share


1 answer


There is an updated plunker

I'm not really sure what you want to do with your root state, so I used it the way I did ...

$stateProvider
    .state('root', {
        abstract: true,
        template: '<div ui-view=""></div>',
        resolve: {
          somedata: function(){return {}}
        }
    })
    .state('home', {
        parent: 'root',
        url: '/home',
        templateUrl: 'listView.html',
        controller: 'ListController'
    })
    .state('about', {
      parent: 'root',
        url: '/about',
        templateUrl: 'resumeView.html'
    })
    .state('items', {
       parent: 'root',
        url: '/items/:itemLink',
        templateUrl: 'itemView.html',    
        controller: 'ItemController'
    });

      



As we can see, the super-parent state has no url and it contains a pattern (where all children are injected) 'root'

On the other hand, each state now declares the parent as "root". This would mean that all states have access to permissive means or any other common material that is later applied to the root.

A simple way to act on all states. Hope this helps. Maybe check this for more details: Angular JS Router Page Reloading - UI does not set state

+1


source







All Articles