0
我要創建指令:爲什麼我在嘗試創建指令時出錯?
這裏是指令的定義:
(function() {
"use strict";
angular.module("siteObjects").directive("myOnOffSwitch", [myOnOffSwitch]);
function myOnOffSwitch() {
return {
restrict: "E",
scope: {
status: "=",
},
template: "<div class='well'>"+
"<i class='fa fa-toggle-on active' ng-if='status == true' ng-click='changeStatus();'></i>"+
"<i class='fa fa-toggle-on fa-rotate-180 inactive' ng-if='status == false' ng-click='changeStatus();'></i>"+
"<div style='display: inline-block;font-size: 30px; float:left;' ng-if='status == true'> on</div>" +
"<div style='display: inline-block;font-size: 30px; float:left;' ng-if='status == false'>off</div>" +
"</div>",
controller: function ($scope) {
$scope.changeStatus = function() {
$scope.status = !$scope.status;
}
}
}
}
})();
在這裏,我如何使用它在我的觀點:
<my-on-off-switch status="list.status"></my-on-off-switch>
我得到這個錯誤:
Error: [$injector:strictdi] function($scope) is not using explicit annotation and cannot be invoked in strict mode
任何想法,爲什麼我得到上述錯誤?
我會建議使用'bindToController',這樣你就不必注入'$ scope',這樣你的代碼變得更加清晰 – LionC