首页 > 解决方案 > 为什么'<'绑定的 currentValue 未定义当我作为 Angular 中的文字字符串传递时

问题描述

你好我有一个绑定说itemType:

这就是我在组件中定义它的方式:

 bindings: {    
     itemType: '<?',
 }

现在由于某种原因,当我将它作为文字字符串而不是属性值传递时,该值没有传递,这就是我的意思,假设我有一个控制器:

someController = function someController( $scope) {
            var self = this;

            self.itemType = 'someString';

在职的:

<some-component>
        open-id="singleSelect"
        item-type="ctrl.itemType"

//..

 itemType.currentValue = 'someString'

不工作:

<some-component>
        open-id="singleSelect""
        item-type="someString"

//..

itemType.currentValue = undefined

标签: angularjs

解决方案


为使用单向('<')绑定绑定的组件属性提供文字字符串时,请使用引号:

<some-component
    open-id="singleSelect"
    ̶i̶t̶e̶m̶-̶t̶y̶p̶e̶=̶"̶s̶o̶m̶e̶S̶t̶r̶i̶n̶g̶"̶ ̶
    item-type="'someString'" >
</some-component>

否则someString被评估为属性标识符。它绑定undefined是因为该属性在范围内不存在。


推荐阅读