AngularJS directive with a Swiffy instance throws error on route navigation -
setup
i have directive takes path json file attribute value, loads json, instantiates swiffy:
angular.module('myapp') .directive('swiffy', function ($http) { return { restrict: 'a', scope: {}, link: function postlink($scope, $element, attrs) { var stage; // listen angular destroy $scope.$on('$destroy', function() { if(stage) { stage.destroy(); stage = null; } }); // load swiffy json $http({ method: 'get', url: attrs.swiffy }).success(function(data, status, headers, config) { stage = new swiffy.stage( $element[0], data ); stage.start(); }).error(function(data, status, headers, config) { }); } }; });
the markup:
<div swiffy="my-animation.json"></div>
i have basic routing setup:
angular .module('myapp', [ 'ngcookies', 'ngresource', 'ngsanitize', 'ngroute' ]) .config(function ($routeprovider) { $routeprovider .when('/', { templateurl: 'views/main.html', controller: 'mainctrl' }) .when('/info', { templateurl: 'views/info.html', controller: 'infoctrl' }) .otherwise({ redirectto: '/' }); });
the controllers here empty.
problem
the json file loads should , swiffy svg created fine. when navigate away view has swiffy directive, angular throws error , whole app breaks:
typeerror: cannot read property '1' of null @ annotate (angular.js:3179:24) @ object.invoke (angular.js:3846:21) @ angular.js:5580:43 @ array.foreach (native) @ foreach (angular.js:323:11) @ object.<anonymous> (angular.js:5578:13) @ object.invoke (angular.js:3869:17) @ angular.js:3711:37 @ object.getservice [as get] (angular.js:3832:39) @ adddirective (angular.js:6631:51)
the error thrown after '$destroy' event has triggered in directive, know stage.destroy() has run on swiffy object.
the angularjs function throws error can found here https://github.com/angular/bower-angular/blob/7ae38b4a0cfced157e3486a0d6e2d299601723bb/angular.js#l3179
as far can tell, annotate() trying read parameters on anonymous function , fails. have no errors if remove swiffy instantiation errors have result of creating swiffy object.
i'm using:
- angularjs 1.2.16
- swiffy runtime version 6.0.2
so far i've tried:
- updating angularjs version 1.2.17-build.111+sha.19d7a12. (it contains update annotate function doesn't fix problem)
- removed 'strict mode' directive.
- removed stage.destroy()
i'd rather not make changes angular.js source (i tried make angular skip anonymous functions broke more things) , swiffy runtime not available un-minified i'm not sure going on in there. ideas great, thanks.
probably little late answer, try upgrading angularjs 1.3 or higher. there blog post problems angularjs 1.2 , svg here:
Comments
Post a Comment