我有以下格式,其中我有一个全局组件,它有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'
});
在主create-goal
html文件中,我有以下内容:
<ui-view goal="$ctrl.goal"
goalInfo="$ctrl.goalInfo"
processStep1="$ctrl.processStep1">
</ui-view>
goal
和goalInfo
效果很好,因为它们是数据绑定的单向数据。但是,当我想传递一个函数(例如processStep1
来计算step-1
上的某些操作等)时,即使step-1
组件中该函数未显示在goal
组件中{1}}和goalInfo
做。
export default {
name: 'step1',
restrict: 'E',
bindings: {
goal: '<',
processStep1: '&'
},
template,
controller
};
思想?
答案 0 :(得分:0)
有几种方法可以做到这一点。
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/