在指令模板中时,以下所有 HTML 片段均因解析错误而失败:
1.
<select ng-model="model" ng-options="s.abbreviation as s.name for s in states" ng-disabled="false"></select>
失败:
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>
$scope.disabled
布尔值 ( )在哪里false
失败:
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>
$scope.isDiabled
函数在哪里失败:
Error: Syntax Error: Token 'isDisabled' is an unexpected token at column 18 of the expression [state.isDisabled isDisabled()] starting at [isDisabled()].
当相同的代码在主 HTML 中时,它运行良好,但ng-disabled
在我将它移到它自己的指令后它停止解析。
这是用于该指令的 JavaScript:
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 };
}
}
}
}
]);
它有什么问题?如果我删除该ng-disabled
属性,它工作正常。