angularjs通过组件将祖父母传递给孙子 [英] angularjs pass grandparent to grandson with components

查看:100
本文介绍了angularjs通过组件将祖父母传递给孙子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可以使用3个组件,请举个例子:

let me give an example if I could with 3 components:

<grandparent>
    <parent>
        <grandson>

如果祖父母有对象,让我们说一个人

If grandparent has an object, let us say a person

const person = {
    name: 'William',
    age: 102
}

孙子将如何从祖父母那里继承价值?

How would the grandson be able to inherit that value from grandparent?

<title={{ $ctrl.person.name }}>

不起作用,因为 $ ctrl 是父级.

won't work because the $ctrl would be the parent.

希望我的例子很简单.

推荐答案

选中此插件a>

这是更新的代码:

<grand-parent>
  <cbs-cus-comp com-bind='grandParentCntAs.name'>
    <child child-com-bind='cbsCusCompCntAs.name'></child>
  </cbs-cus-comp>
</grand-parent>

您需要提供以下类似内容才能实现此目的:

You need to provide something like below to make that happen:

  var cbsCusComp        =   {
                            transclude  :   true,
                            require: {grandParentComp:'^grandParent'},
                            template    :   'Parent : <b>{{cbsCusCompCntAs.comBind}}</b><br /><ng-transclude></ng-transclude>',
                            controller  :   cbsCusCompCnt,
                            controllerAs:   'cbsCusCompCntAs',
                            bindings    :   {comBind:'='}
                        };

这篇关于angularjs通过组件将祖父母传递给孙子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆