angularjs – 如何将特定绑定传递给Angular 1.5中组件路由器引入
我希望能够将参数传递给ng-outlet引入的子组件.但我不知道该怎么做.
这是我的组件绑定的示例: app.component('profile',{ bindings: { section: '=',currentUser: '<' },... 通常我会这样调用: <profile section="$ctrl.bio" current-user="$ctrl.selectedUser"></profile> 但相反,我有这个: <ng-outlet></ng-outlet> 和一个传递配置文件的路由器. $routeConfig: [ { path: '/Profile/:id',name: 'Profile',component: 'profile' }] 那么如何将火焰传递给此组件的其他基本绑定(可能是无法编码到URL中的绑定)? 谢谢,非常感谢帮助 编辑:我被要求提供一个更具体的例子,说明我想做什么. 我认为概念问题相当清楚,但这是一个特殊情况,其中传递路线参数显然是不够的.在我的App组件级别说我有一个事件回调函数onDeleteItem(id) 我该如何复制 bindings: { onDeleteItem: "&" } ... <some-component on-delete-item="$ctrl.onDeleteItem(id)"></some-component> 有一个出口?
我查看了
docs并看到了路由器中使用的其中一个组件
所以我很好想,如果可以填充该绑定,那么为什么我们不能为其他绑定传递数据,但是我查看了组件路由器的来源,实际上我没有看到传递数据的方法办法.这是因为它看起来像是specially handling passing in the $router,但我不认为模板在此之后被修改: activate(instruction) { ... this.controller.$$template = '<' + dashCase(componentName) + ' $router="::$$router"></' + dashCase(componentName) + '>'; ... }; 我会说,你应该能够使用数据传递到组件 $routeConfig: [ { path: '/Profile/:id',component: 'profile',data: { item1: 'item1'} }] 然后在组件的构造函数中注入RouteData,但我认为这只是在角度2中,因为我没有在angular 1路由器中看到它的实现. 所以根据我所做的研究,我认为你不能,或者很难.另外,相关:How to inject data into Angular2 component created from a router和https://github.com/angular/angular/issues/4452 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |