[英]How to pass down a callback from a parent component to a nested routed component?
I have the following format where I have a global component that has 3 nested components that are activated based on a given route: 我有以下格式,其中我有一个全局组件,该组件具有3个嵌套组件,这些嵌套组件根据给定的路线被激活:
$stateProvider
.state('create-goal', {
url: '/create-goal',
component: 'createGoal',
redirectTo: 'create-goal.step-1'
})
.state('create-goal.step-1', {
url: '/step-1',
component: 'step1'
})
.state('create-goal.step-2', {
url: '/step-2',
component: 'step2'
})
.state('create-goal.step-3', {
url: '/step-3',
component: 'step3'
});
Inside of the main create-goal
html file, I have the following: 在主要的
create-goal
html文件中,我具有以下内容:
<ui-view goal="$ctrl.goal"
goalInfo="$ctrl.goalInfo"
processStep1="$ctrl.processStep1">
</ui-view>
The goal
and goalInfo
work great as they are data that is one way data bound. goal
和goalInfo
工作,因为它们是数据的一种数据绑定方式。 However, when I want to pass down a function, such as processStep1
to compute some action on step-1
and so forth, that function does not show up in the step-1
component even though the goal
and goalInfo
do. 但是,当我想传递诸如
processStep1
类的功能以计算对step-1
某些操作等等时,即使goal
和goalInfo
都可以在step-1
组件中显示该功能。
export default {
name: 'step1',
restrict: 'E',
bindings: {
goal: '<',
processStep1: '&'
},
template,
controller
};
Thoughts? 思考?
There a few ways you could go about doing this. 您可以通过几种方法执行此操作。
https://docs.angularjs.org/guide/directive http://fdietz.github.io/recipes-with-angular-js/controllers/sharing-code-between-controllers-using-services.html https://www.sitepoint.com/tidy-angular-controllers-factories-services/ http://www.webdeveasy.com/angularjs-data-model/ https://docs.angularjs.org/guide/directive http://fdietz.github.io/recipes-with-angular-js/controllers/sharing-code-between-controllers-using-services.html https:// www.sitepoint.com/tidy-angular-controllers-factories-services/ http://www.webdeveasy.com/angularjs-data-model/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.