我正在尝试找到一个更好的解决方案来ui-router
与angular 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>'
});
现在,我正在使用template
属性指定组件及其参数:
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>"
})
});
虽然这工作正常,但我的组件有十个绑定,这使得配置非常ui-router
尴尬。
我尝试使用该component
属性,但这对我根本不起作用。我发现的唯一其他解决方案是使用require
属性指定父级并省略绑定 - 但这对我来说感觉不合适......有没有更好的方法来做到这一点?
这是一个plnkr。