Recently I started working with Angular and now I'm attempting to extract the project ID from the URL and use it as a variable within a service.
Here's my current code snippet:
app.config(
['$routeProvider',
function($routeProvider) {
...
$routeProvider.when('/project/:ProjectId', {
templateUrl: 'project.html',
controller: 'ProjectController',
activePage: 'Portfolio'
});
...
}
])
...
.controller('ProjectController', function($scope, ProjectFactory) {
$scope.content = ProjectFactory.async();
})
...
.factory('ProjectFactory', function($http) {
var factoryProject = {
async: function(page) {
var projectId = 'XXXXXX';
var apiKey = 'XXXXXX';
var url = 'http://behance.net/v2/projects/' + projectId + '?api_key=' +
apiKey + '&callback=JSON_CALLBACK';
var promise = $http.jsonp(url).error(function(response, status) {
alert(status);
}).success(function(response, status) {
console.log(response.project);
}).then(function(response, status) {
return response.data;
});
return promise;
}
};
return factoryProject;
});
I feel like I'm overlooking something. How can I store the :ProjectId from $routeProvider into the projectID variable?
Appreciate your help!