2

I'm using AngularJS 1.5.11.

I can't seem to get my component wired-up correctly. If I hard-code a template property, it works:

$stateProvider.state("dashboard.expense", {
  url: "/expense",
  template: `<div>Geddy Lee</div>`
})

^^ That indeed shows Geddy Lee on the page.

But as soon as I point it to a component, no rendering occurs:

$stateProvider.state("dashboard.expense", {
  url: "/expense",
  component: "expenseReportsComponent"
})

I'm keeping the component simple, just to see if I can get it to render:

module.component('expenseReportsComponent', {
  template: `<div>Geddy Lee</div>`
});

^^ Geddy Lee is not displayed.

There are no console errors. I've tried a variety of changes, but nothing seems to work. What am I missing?

3 Answers 3

3

You are very likely to use old version of ui-router. Either migrate to newer one or use:

template: `<expense-reports-component></expense-reports-component>`

you wont have all features like uiOnParamsChanged in this case, but this of course will work.

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

1 Comment

Thanks. I just tried using the template property like that and it didn't work for me. Looks like I just need to update ui-router.
1

Double check to see what version of ui-router you are using. I believe the component property was added in 1.0.0.

https://github.com/angular-ui/ui-router/blob/master/CHANGELOG.md

Comments

0

Combine it all together and use both template and component in your state declaration:

$stateProvider.state("dashboard.expense", {
  url: "/expense",
  template: `<div>Geddy Lee</div>`,
  component: "expenseReportsComponent"
})

1 Comment

I don't think that helps me. This is just a test to see that I can get a component working. Once I do, I'm going to start using a more complex component. Plus, I believe the component property is supposed to take the place of the template and controller properties.

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.