带有Swiffy实例的AngularJS指令在路线导航上引发错误 安装程序
我有一个指令,它将json文件的路径作为属性值,加载json,然后实例化Swiffy:带有Swiffy实例的AngularJS指令在路线导航上引发错误 安装程序,angularjs,google-swiffy,Angularjs,Google Swiffy,我有一个指令,它将json文件的路径作为属性值,加载json,然后实例化Swiffy: angular.module('myApp') .directive('swiffy', function ($http) { return { restrict: 'A', scope: {}, link: function postLink($scope, $element, attrs) { var stage; //
angular.module('myApp')
.directive('swiffy', function ($http) {
return {
restrict: 'A',
scope: {},
link: function postLink($scope, $element, attrs) {
var stage;
// Listen to 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) {
});
}
};
});
标记:
<div swiffy="my-animation.json"></div>
这里的控制器是空的
问题
json文件按其应该的方式加载,Swiffy svg创建得很好。但当我离开一个有快速指令的视图时,angular会抛出一个错误,整个应用程序都会中断:
TypeError: Cannot read property '1' of null
at annotate (angular.js:3179:24)
at Object.invoke (angular.js:3846:21)
at angular.js:5580:43
at Array.forEach (native)
at forEach (angular.js:323:11)
at Object.<anonymous> (angular.js:5578:13)
at Object.invoke (angular.js:3869:17)
at angular.js:3711:37
at Object.getService [as get] (angular.js:3832:39)
at addDirective (angular.js:6631:51)
TypeError:无法读取null的属性“1”
在注释处(angular.js:3179:24)
在Object.invoke(angular.js:3846:21)
在angular.js:5580:43
at Array.forEach(本机)
在forEach(angular.js:323:11)
反对
据我所知,annotate()试图读取匿名函数的参数,但失败了。如果删除Swiffy实例化,则没有错误,因此这些错误必须是创建Swiffy对象的结果
我正在使用:
- AngularJS 1.2.16
到目前为止,我已经尝试:
- 更新至AngularJS版本1.2.17-build.111+sha.19d7a12。(它包含对annotate函数的更新,但这并不能解决问题)
- 从指令中删除了“严格模式”
- 删除stage.destroy()
我不希望对angular.js源代码做任何更改(我尝试使用angular skip匿名函数,但这破坏了更多功能),而且swiffy运行时在未缩小的情况下不可用,因此我不确定那里发生了什么。任何想法都很好,谢谢
TypeError: Cannot read property '1' of null
at annotate (angular.js:3179:24)
at Object.invoke (angular.js:3846:21)
at angular.js:5580:43
at Array.forEach (native)
at forEach (angular.js:323:11)
at Object.<anonymous> (angular.js:5578:13)
at Object.invoke (angular.js:3869:17)
at angular.js:3711:37
at Object.getService [as get] (angular.js:3832:39)
at addDirective (angular.js:6631:51)