Last active
December 16, 2015 07:48
-
-
Save davemo/5401166 to your computer and use it in GitHub Desktop.
An example of routes that depend on pre-fetched data prior to rendering, the template, controllers that handle form submission, and relevant service abstraction in AngularJS.
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
app.config ($routeProvider) -> | |
$routeProvider.when '/settings', | |
templateUrl: 'settings.html' | |
controller: 'SettingsController' | |
resolve: | |
settings: (SettingsService) -> SettingsService.get() |
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
<form name="settingsForm" ng-submit="saveSettings()"> | |
<label>Email</label> | |
<input ng-model="settings.email" type="email" required/> | |
<button type="submit">Save Settings</button> | |
</form> |
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
app.controller 'SettingsController', ($scope, settings, SettingsService) -> | |
$scope.settings = settings.data | |
$scope.saveSettings = -> | |
SettingsService.put($scope.settings) |
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
app.factory 'SettingsService', ($http) -> | |
url = "/settings" | |
get: -> $http.get(url) | |
put: (settings) -> $http.put(url, settings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment