gpt4 book ai didi

javascript - Angular 1.5 指令 bool 值未传递到范围内

转载 作者:行者123 更新时间:2023-11-29 17:59:49 25 4
gpt4 key购买 nike

我有一个指令:

var myApp = angular.module('myApp', []);

var HelloDirective = function() {
return {
scope: {
list: "=",
showValue: "="
}, // use a new isolated scope
restrict: 'AE',
replace: false,
template: '<h3>List value is {{list}}</h3><br/>Raw value is [{{showValue}}] <br/><br/>showValue value is: <span ng-show="showValue">True</span><span ng-hide="showValue">False</span>'

};
}

myApp.directive("helloDirective", HelloDirective);

myApp.controller('MyCtrl', function($scope) {
$scope.name = 'Angular Directive';
$scope.osList = "Original value";
$scope.bv = true;
})

这是我的 HTML:

<div ng-controller="MyCtrl">
Hello, {{name}}! Value is {{bv}}
<p list="osList" showValue="bv" class="" hello-directive></p>
</div>

这是输出:

Hello, Angular Directive! Value is true

List value is Original value

Raw value is []

showValue value is: False

oList 显示正确但 showValue 没有正确传递 bool 值,这是怎么回事?看到这个 fiddle :

https://jsfiddle.net/mbaranski/guq2qyuc/12/

最佳答案

它(属性)应该是 show-value="bv" 而不是 showValue="bv"

关于javascript - Angular 1.5 指令 bool 值未传递到范围内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35815209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com