All of the following HTML snippets fail with parsing errors when in a directive template:
1.
<select ng-model="model" ng-options="s.abbreviation as s.name for s in states" ng-disabled="false"></select>
fails with:
Error: Syntax Error: Token 'false' is an unexpected token at column 18 of the expression [state.isDisabled false] starting at [false]
2.
<select ng-model="model" ng-options="s.abbreviation as s.name for s in states" ng-disabled="disabled"></select>
where $scope.disabled is a boolean (false) fails with:
Error: Syntax Error: Token 'disabled' is an unexpected token at column 18 of the expression [state.isDisabled disabled] starting at [disabled].
3.
<select ng-model="model" ng-options="s.abbreviation as s.name for s in states" ng-disabled="isDisabled()"></select>
where $scope.isDiabled is a function fails with:
Error: Syntax Error: Token 'isDisabled' is an unexpected token at column 18 of the expression [state.isDisabled isDisabled()] starting at [isDisabled()].
When the same code was in the main HTML, it worked fine, but it stopped parsing ng-disabled after I moved it to its own directive.
This is the JavaScript used for this directive:
myApp.directive("selectState", [
function () {
var states = [ // src: https://gist.github.com/mshafrir/2646763
{ "name": "Alabama", "abbreviation": "AL" } /*, { .. }, { .. }*/
];
return {
templateUrl: "/directives/select-state/select-state.html",
replace: true,
scope: { model: "=", isDisabled: "=" },
restrict: "EA",
controller: function ($scope, $element, $attrs) {
$scope.states = states;
$scope.disabled = false;
if (!$scope.isDisabled) {
$scope.isDisabled = function () { return false };
}
}
}
}
]);
What is wrong with it? If I remove the ng-disabled attribute, it works fine.