简体   繁体   English

AngularJS 1.6.x组件包含范围问题

[英]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.

相关问题 AngularJS 1.6.x:无法读取未定义的属性“条目” - AngularJS 1.6.x: Cannot read property 'entry' of undefined 为什么此angularjs测试只能在1.5.x中工作而不能在1.6.x中工作? - Why does this angularjs test work in 1.5.x but not in 1.6.x? Angular 1.6.x,如何将组件标签从当前组件渲染到html - Angular 1.6.x , how to render component tag from current component to html 复选框作用域已绑定,但即使在angular.js 1.6.x中使用点也不会更新 - checkbox scope is binding but not updating even with dot in angular.js 1.6.x 在Azure Node.js Web应用程序上运行angularjs 1.6.x,长网址导致404服务器错误 - Running angularjs 1.6.x on azure node.js webapp, long url causes a 404 server error AngularJS 1.6.x使用html字符串和ng-if =“ {{}}”动态加载组件 - AngularJS 1.6.x Dynamically Load Components with html string and ng-if=“{{ }}” ui-router $ stateProvider文本参数未与ui-view,AngularJS 1.6.x一起显示 - ui-router $stateProvider text parameter not displaying with ui-view, AngularJS 1.6.x AngularJS覆盖范围的超越范围 - AngularJS override scope of transclude scope AngularJS指令包含父范围 - AngularJS Directive Transclude parent scope AngularJS指令转换scope = false? - AngularJS directive transclude scope=false?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM