On Github tszewcow / starter-kit-angular-js
Tomasz Szewców
# install the Yoeman globally using Node Package Manager npm install -g yo # install the OASP template generator-oasp globally npm install -g generator-oasp # make a directory for the template and navigate to it mkdir directory_name cd directory_name # Call the generator in the selected directory yo oasp # start the app using gulp gulp serve
// define a module without dependencies
angular.module('moduleName', []);
// define a module with dependencies
angular.module('moduleName', ['dependency1', 'dependency2']);
// retrieve a module
angular.module('moduleName');
<!--Bootstrap application--> <div ng-app="moduleName"></div>
angular.module('moduleName').controller('SomeController', function($scope, someService){
'use strict';
// add something to injected $scope
$scope.data = {};
// call injected service method
someService.someMethod();
};
angular.module('someModule').controller('MyFirstController', function($scope){
'use strict';
$scope.helloWorld = 'hello world!';
alert($scope.helloWorld);
});
<!--use controller in the dialog template with the ng-controller directive -->
<!DOCTYPE html>
<html>
<body>
<section data-ng-controller="MyFirstController">
<h2>Hello from Dialog A!</h2>
</section>
</body>
</html>
angular.module('someModule').service('myService', function(){
'use strict';
this.print = function(){
alert('hello world from a service');
};
});
angular.module('someModule').factory('myService2', function(){
'use strict';
var helloWorld = 'hello world from a service2';
return {
print: function(){
alert(helloWorld);
}
};
});
// Simple GET request example:
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
// shortcut methods
$http.get('/someUrl', config).then(successCallback, errorCallback);
$http.post('/someUrl', data, config).then(successCallback, errorCallback);
angular.module('moduleName', []).config(function ($routeProvider) {
$routeProvider.when('/tables', {
templateUrl: '/table-mgmt/html/tables.html',
controller: 'TablesCntl'
}).when('/table-view', {
templateUrl: '/table-mgmt/html/table-details.html',
controller: 'TableDetailsCntl'
});
});
angular.module('moduleName', []).config(function ($routeProvider) {
$routeProvider.when('/books', {
templateUrl: '/table-mgmt/html/tables.html',
controller: 'TablesCntl',
resolve: {
// the 'tables' function is injectable
tables: function(){
//return data or promise and inject into controller
}
}
});