是否有一种方法可以确定指令范围“&"项已设置为某个内容

Is there a way to determine whether a directive scope "&" item has been set to something?

本文关键字:amp quot 设置 范围 一种 方法 定指 指令 是否      更新时间:2023-09-26

在以下注意事项中,bar没有值。

实例:

<my-directive
    foo="foo"
    bar="" /></my-directive>

指令:

return function() {
    return {
        restrict: 'E',
        scope: {
            foo: '&',
            bar: '&',
        },
        template: template,
        controllerAs: 'ctrl',
        controller: controller,
    };
};

如何在控制器中告知scope.bar未设置为任何值?

我使用的是Angular 1.4。

属性值本身可以使用进行检查

$attrs.bar == true;

正如前面所提到的,&绑定会产生始终真实的包装器函数。