Skip to content

Instantly share code, notes, and snippets.

@stursby
Last active August 29, 2015 14:14
Show Gist options
  • Save stursby/5f67939fac39a0bf1ef1 to your computer and use it in GitHub Desktop.
Save stursby/5f67939fac39a0bf1ef1 to your computer and use it in GitHub Desktop.
Plangular

Getting the following Console error:

http://api.soundcloud.com/resolve.json?callback=angular.callbacks._0&client_id=0d33361983f16d2527b01fbf6408b7d7&url=soundcloudURL

I'm guessing it's because the directive is running before the Firebase call retuns the URL... so how do I reload the plangular directive? Or defer loading the directive until I have the SoundClour URL because the URL will be different for each room.

<div class="table" ng-if="urlIsLoaded" // added this to defer loading
plangular="{{ soundcloudURL }}"> // must use curly braces too
<div class="table-cell">
<button class="button-icon" ng-click="playPause()">
<svg ng-if="player.playing != track" plangular-icon="play"></svg>
<svg ng-if="player.playing == track" plangular-icon="pause"></svg>
</button>
</div>
<div class="table-cell px2 full-width">
<h3 class="m0">{{ user.username }}</h3>
<p>{{ title }}</p>
<progress value="{{ currentTime / duration || 0 }}"
ng-click="seek($event)">
{{ currentTime / duration }}
</progress>
<small>{{ currentTime | prettyTime }} | {{ duration | prettyTime }}</small>
</div>
</div>
/* global Firebase */
(function(angular) {
'use strict';
angular.module('tunesApp')
.controller('RoomCtrl', function(
$scope,
$rootScope,
$routeParams,
$timeout,
$location,
$firebase,
FBURL
) {
var roomRef = new Firebase(FBURL).child('rooms/' + $routeParams.id);
$scope.urlIsLoaded = false;
// Working now and wrap in $timeout to update scope immediately.
roomRef.once('value', function(snapshot) {
var val = snapshot.val();
$timeout(function() {
$scope.soundcloudURL = val.url;
$scope.urlIsLoaded = true;
});
});
});
})(window.angular);
@stursby
Copy link
Author

stursby commented Jan 24, 2015

Nice, that worked... I'll update the above code to reflect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment