I am trying to find a better solution to use the ui-router
together with angular components
.
Consider two simple components:
app.component('componentOne', {
template: '<h1>My name is {{$ctrl.name}}, I am {{$ctrl.age}} years old.</h1>',
bindings : {
name : '@',
age : '@'
}
}
);
app.component('componentTwo', {
template: '<h1>I am component 2</h1>'
});
Right now, I am specifying the component and its parameter using the template
property:
app.config(function($stateProvider, $urlRouterProvider ){
$stateProvider
.state('component1', {
url: "/component1",
template: "<component-one name=\"foo\" age=\"40\"></component-one>"
})
.state('component2', {
url: "/component2",
template: "<component-two></component-two>"
})
});
While this is working fine, I have components with arround ten bindings which makes the configuration of the ui-router
realy awkward.
I tried using the component
property but this doesn't work for me at all. The only other solution I found is to specify the parent using the require
property and omit the bindings - but this doesn't feel right for me... Is there a better way to do this?
Here is a plnkr.