Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kjir/683a61a28a1f92ab71a3fd4a0e2abef7 to your computer and use it in GitHub Desktop.
Save Kjir/683a61a28a1f92ab71a3fd4a0e2abef7 to your computer and use it in GitHub Desktop.
Fetch data before loading angular app
div(ng-app="mymodule")
angular.module 'mymodule', []
.run ($http) !->
$http.get 'https://api.chucknorris.io/jokes/random'
.then (resp) !->
angular
.module 'othermodule'
.constant 'joke', resp.data.value
.finally !->
angular.bootstrap document, ['othermodule']
angular.module 'othermodule', ['mod.service']
.config (joke, myServiceProvider) !->
myServiceProvider.setJoke joke
.run (myService) !->
myService.hello()
angular.module 'mod.service', []
.provider 'myService', !->
var joke
this.setJoke = (j) !->
joke := j
this.$get = !->
return
hello: !->
console.log("Joke of the day:", joke)
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment