1

I can't seem to get my 'nameDisplay' component to display when I change the url to '/nameDisplay'. It doesn't display any error, it just doesn't insert the template into the ui-view. If I use template in the 'state' instead of component then it works otherwise it displays nothing.

The versioning I'm using is: angular - 1.5.8 angular ui router - 0.3.1

angular.module('app.nameDisplay', [uiRouter])
.component('nameDisplay', {
    controller: function(){
        this.name = "Keir Beckett";
        this.age = 24;
        this.changeInfo = function(){
            this.name = "Golash Bista";
            this.age = 66;
        }
    },
    template: "" +
        "<div>" +
            "<h2>{{$ctrl.name}}</h2>" +
            "<h4>{{$ctrl.age}}</h4>" +
            "<button ng-click='$ctrl.changeInfo()'>Change Info</button>" +
        "</div>"
}).config(($stateProvider, $urlRouterProvider) => {
    $stateProvider.state('nameDisplay', {
        url: '/nameDisplay',
        component: 'nameDisplay'
    })
    .state("otherDisplay", {
        url: '/otherDisplay',
        template: '<h1>Other Display</h1>'
    });
    $urlRouterProvider.otherwise('/');
})
.name;
1
  • 1
    I've never seen component as a property of a state object... is this a new syntax? Usually, this is done by having a template: '<name-display></name-display>'. Commented Aug 11, 2016 at 13:45

1 Answer 1

4

Using components directly in the ui-router config only works from ui-router 1.0.0 on. So you should either upgrade to the (currently still) beta version or use the 0.3.x style to include components using a template for <name-display></name-display>.

See my answer for a similar question here: Angular 1.5 - UI-Router, Resolve Object returning undefined values

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.