我有一個指令:角1.5指令布爾值不會傳遞到範圍
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>
這裏是輸出:
你好,角指示!值爲true
列表值是原值
原始值[]
showValue值是:假
oList顯示正常,但showValue不適當地傳遞布爾,什麼是錯的?看到這個小提琴:
https://jsfiddle.net/mbaranski/guq2qyuc/12/
角的[文件](https://docs.angularjs.org/guide/directive)使用術語'camelCase'但很好的回答乾脆( _Angular規範化元素的標籤和屬性名稱,以確定哪些元素匹配哪些指令。我們通常通過區分大小寫的camelCase規範化名稱(例如ngModel)來引用指令_) –