I am trying to write a loader using AngularJS using directive and spin.js (which does not use jQuery).
I know that AngularJS has its own jQuery lite. However, I cannot get width from element in the directive.
Basically, I need to get the width of the button (inside the directive)
I have tried so far:
element[0].width // < - error angular.element(element[0]).css('width') // < - undefined
Here we go:
Demo at Plunker
HTML
<button type="submit" loader left="5" ng-click="loadData()" >Load Data</button>
Js
var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope, stockData, $timeout) { $scope.loadData = function(){ $scope.init(); stockData.query() .then(function (result) { $timeout(function () { $scope.data = result.data; $scope.stop(); return result.data; }, 3000); }, function (result) { alert("Error: No data returned"); }); } }); app.directive('loader', ['$parse', 'stockData', '$timeout', function ($parse, stockData, $timeout) { return { restrict: 'A', link: function (scope, element, attr) { var spinner; var opts = { lines: 13,
Thanks,
angularjs
Maxim shoustin
source share