我有一個簡單angularjs指令,當我再壓縮文件,因爲變量名稱更改如何正確縮小angularJS文件
var app= angular.module('app',[]);
app.directive('directive',function(){
return {
restrict: 'EA',
scope: {},
replace: true,
link: function($scope, element, attributes){
$scope.name="test-test";
,
controller: function($scope,$attrs,$http){
},
templateUrl: 'directives/app/app.tpl.html'
}
});
問題是$ scope.name變成a.name和我得到錯誤角度無法識別它。 我試圖通過嘗試類似
link: ['$scope',function($scope, element, attributes){
$scope.name="test-test";
}],
controller: ['$scope','$attrs','$http',function($scope,$attrs,$http){
}],
但精縮時,我仍然得到a.name的同樣的錯誤注入$範圍。
鏈接功能不使用依賴注入。這實際上是你正在測試的確切代碼嗎?你的原始代碼的鏈接功能應該工作正常,你的控制器應該拋出一個關於未知供應商的錯誤 – rob
是的,這是確切的代碼(我是angularJS的新手,並與它一起玩耍)。它確實拋出錯誤之前,但試圖注入後它不會拋出任何錯誤,但數據綁定不起作用,我看到a.name而不是$ scope.name – krs8888
你是故意試圖使用'$ scope'來代替即使你在你的指令中指定了一個獨立的範圍,你的鏈接函數中的「範圍」是什麼? –