2015-11-11 41 views
0

我想縮小我的app.js代碼(嘗試了幾個在線工具)。但是我得到了問題中提到的錯誤。這是我的代碼:錯誤:意外的令牌punc«)»,期望punc«,»同時縮小angularjs應用

(function() { 
    var app = angular.module('LazyApp', []); 
    app.directive('lazyLoad', ['$window', function($window) { 
     return { 
      restrict: 'A', 
      scope : {}, 
      link: function(scope, element, attrs) { 
       var images = Array.prototype.slice.call(element[0].querySelectorAll("img[data-src]")); 
       var videos = Array.prototype.slice.call(element[0].querySelectorAll("iframe[data-src]")); 
      } 
     } 
    }) 
}])(); 

我在做什麼錯?

+0

'['之前,你的功能標籤是問題.. –

+1

@KishoreSahas不完全,但括號和方括號絕對看起來不匹配 – Phil

+0

我剛剛意識到我沒有添加'$窗口'就在我的功能之前。 –

回答

3

我想你想這

(function() { 
    angular.module('LazyApp', []) 
    .directive('lazyLoad', ['$window', function($window) { 
     return { 
      restrict: 'A', 
      scope : {}, 
      link: function(scope, element) { 
       var images = Array.prototype.slice.call(element[0].querySelectorAll("img[data-src]")); 
       var videos = Array.prototype.slice.call(element[0].querySelectorAll("iframe[data-src]")); 
      } 
     }; 
    }]) 
})(); 

你不得不在錯誤的地方你的指令構造右方括號。

+0

謝謝你的工作!我的錯! –

相關問題