Last active
November 2, 2015 05:45
-
-
Save shangoyanyi/0ad732f12b4ccdcf8542 to your computer and use it in GitHub Desktop.
Angular - do Parse Query in Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* get recipe object from parse | |
* Object from parse query is not controlled by $scope, so using defer to pass it to $scope | |
*/ | |
// call $q.defer() | |
var RecipeDfd = $q.defer(); | |
// call parse query and resolve it | |
var Recipe = Parse.Object.extend("Recipe"); | |
var query = new Parse.Query(Recipe); | |
query.get(recipeId , { | |
success: function(recipe) { | |
console.log(JSON.stringify(recipe)); | |
RecipeDfd.resolve(recipe); | |
}, | |
error: function(object, error) { | |
console.log(error); | |
RecipeDfd.reject(recipe); | |
} | |
}); | |
// now the parse object is under control of $scope | |
RecipeDfd.promise.then(function (recipe) { | |
$scope.videoName = recipe.get("video").name; | |
$scope.videoUrl = $sce.trustAsResourceUrl(recipe.get("video").url); | |
$scope.url = $sce.trustAsResourceUrl(location.href); | |
$scope.steps = recipe.get('steps'); | |
}).catch(function (error) { | |
console.log(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment