Angularjs + Spotify Views API (1.0): DOM Error Exception 8 -
i'm writing simple angularjs directive communicate spotify api (1.0). i've custom directive should create spotify list
view (reference here: https://developer.spotify.com/docs/apps/views/1.0/list-list.html).
here's angular directive:
angular.module('spotify.view.list', []) .directive('splist', function($rootscope, $timeout) { var rootscope = $rootscope return { restrict: 'ea', replace: true, link: function($scope, el, attrs) { var fn = attrs['for'], list = null, playlist attrs.$observe('uri', function(newval, oldval) { require(['$views/list#list', '$api/models'], function(list, models) { if(newval != oldval && list == null) { playlist = models.playlist.fromuri(attrs.uri) list = list.forplaylist(playlist, { layout: 'default', header: attrs.header||'no', fields: attrs.fields.split(','), height: attrs.height||'fixed', numitems: 10 }) var targetel = document.getelementbyid(attrs.node) targetel.appendchild(list.node) list.init() } }) }) } } })
and how call directive inside angular template:
<div class="playlist-tracklist" id="sp-playlist"></div> <sp-list for="playlist" fields="track,artist" header="yes" type="tracks" layout="default" uri="{{playlist.playlist_uri}}" node="sp-playlist"> </sp-list>
the problem here randomly domexception error
:
uncaught error: notfounderror: dom exception 8
this's totally random: works , spotify list, won't , console doesn't give me other debugging info.
i cannot find way reproduce exception, guess it's have targetel
.
i'd love know why trying append list abritrary html element fails, if html element exists sure, , cause of exception.
i think may re-inserting script tags each time call require; library not caching of modules. believe dom exception happens when script tag times out reason (server not return 304 or 200). try loading modules outside of angular directive , can try , verify if loading script tags more necessary?
Comments
Post a Comment