Skip to content

Instantly share code, notes, and snippets.

@dshster
Created February 16, 2016 13:07
Show Gist options
  • Save dshster/5374dffbda08e7a427aa to your computer and use it in GitHub Desktop.
Save dshster/5374dffbda08e7a427aa to your computer and use it in GitHub Desktop.
Angular bootstrap
var application = 'application';
angular.module(application, ['ngMockE2E']);
angular.module(application)
.controller('SampleController', function(SampleServices) {
var Sample = this;
SampleServices.getServerData().then(function(result) {
Sample.serverData = result;
}, function(error) {
Sample.error = error;
});
});
angular.module(application)
.factory('SampleServices', function($q, $http) {
var SampleServices = {
getServerData: function() {
return $q(function(resolve, reject) {
$http({
method: 'GET',
url: '/api/sample'
}).success(resolve).error(reject);
});
}
};
return SampleServices;
});
angular.module(application)
.run(function($httpBackend) {
$httpBackend.whenGET(new RegExp('/api/sample')).respond(function(method, url, data) {
return [200, {data: {foo: 'bar'}}];
});
});
{
"name": "Angular1",
"authors": [
"Dmitry Shvalyov <[email protected]>"
],
"description": "",
"main": "",
"moduleType": [],
"license": "MIT",
"homepage": "",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular-mocks": "^1.5.0",
"angular": "^1.5.0"
}
}
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-mocks/angular-mocks.js"></script>
<script src="application.js"></script>
<title>Document</title></head>
<body ng-app="application">
<div ng-controller="SampleController as Sample">
{{Sample}}
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment