Created
June 11, 2013 22:30
-
-
Save wvuong/5761342 to your computer and use it in GitHub Desktop.
Context paths and AngularJS
This file contains hidden or 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
<script> | |
// inject inlined constants | |
angular.module('app.constants', []) | |
.constant('contextPath', '${pageContext.request.contextPath}'); | |
</script> |
This file contains hidden or 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
// create the filter that uses the context path constant | |
angular.module('app.filters', ['app.constants']) | |
.filter('relativeUrl', ['contextPath', function(contextPath) { | |
return function(url) { | |
return contextPath + url; | |
}; | |
}]); | |
// inject the filter and use the context path | |
angular.module('app.services', ['ngResource']). | |
factory('PlaceService', ['$filter', '$resource', function($filter, $resource) { | |
var relativeUrl = $filter('relativeUrl'); | |
return $resource(relativeUrl('/rest/places/:id'), {id: '@id'}); | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@wvong
Is there no need to declare
app.filters
as a dependency at line10
inexample.js
forrelativeUrl
filter to work?Refer to: https://gist.github.com/dostiharise/f35a652a8e499d19d245