[英]AngularJS 1.6.x Component Transclude Scope Issue
How to do get access to the parent binding in my child transclude usage? 如何获得对我孩子的父级绑定的访问权限?
Parent Component: 父组件:
<div class="wizard-container" ng-animate="transitionClass">
<section>
<nav>
<ol class="cd-breadcrumb triangle align-center align-item">
<li ng-repeat="breadCrumb in vm.breadcrumbs track by $index" ng-class="{ current: $index + 1 === vm.page}" >
<em><i class="fa {{breadCrumb.icon}}" aria-hidden="true"></i>{{breadCrumb.title}}
</em>
</li>
</ol>
</nav>
<div>
<ng-transclude></ng-transclude>
</div>
</section>
</div>
...
Here is the wizard Controller: 这是向导控制器:
app.controller('wizardController', wizardController);
wizardController.$inject = ['$scope', '$compile'];
function wizardController($scope, $compile) {
var vm = this;
vm.page = 1;
vm.next = true;
vm.previous = false;
vm.nextPage = function () {
vm.page < vm.breadcrumbs.length ? vm.page += 1 : vm.page;
vm.next = true;
vm.previous = false;
};
vm.previousPage = function () {
vm.page > 1 ? vm.page -= 1 : vm.page;
vm.previous = true;
vm.next = false;
};
vm.submit = function () {
vm.page = 1;
vm.next = true;
vm.previous = false;
}
};
app.component("wizard", {
template: require('./wizard.component.html'),
controllerAs: "vm",
controller: wizardController,
bindings: {
breadcrumbs: '<',
wizardPages: '<',
page: '='
},
transclude: true
});
Here is the usage: 这是用法:
<wizard breadcrumbs="vm.breadcrumbs" wizard-pages="vm.wizardPages" page="1">
<div ng-if="vm.page === 1" ng-class="{ 'next': vm.next, 'previous': vm.previous }">
<service-center-branch-selection>
</service-center-branch-selection>
</div>
</wizard>
How do I get access to vm.page that gets set by the wizard(parent) component? 我如何访问由向导(父)组件设置的vm.page? Right now vm.page, vm.next, and vm.previous are not updating properly.
目前,vm.page,vm.next和vm.previous无法正确更新。
I'm not sure if I did understand you correctly. 我不确定我是否正确理解了您。
If you want to get access to a parent component add require to a child component like this: 如果要访问父组件,请向子组件添加require,如下所示:
require: { parentComponent: '^^' }
Then you should get access to these data: 然后,您应该可以访问以下数据:
this.parentComponent.page
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.