A Pen by Stéphane Bisinger on CodePen.
Created
July 14, 2016 17:19
-
-
Save Kjir/683a61a28a1f92ab71a3fd4a0e2abef7 to your computer and use it in GitHub Desktop.
Fetch data before loading angular app
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
div(ng-app="mymodule") |
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
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) |
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 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