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
You can think of a module as a container for the different parts of your app – controllers, services, filters, directives, etc.
// define a module without dependencies
angular.module('moduleName', []);
// define a module with dependencies
angular.module('moduleName', ['dependency1', 'dependency2']);
// retrieve a module
angular.module('moduleName');
Dependency Injection (DI) is a software design pattern that deals with how components get hold of their dependencies.
The Angular injector subsystem is in charge of creating components, resolving their dependencies, and providing them to other components as requested.
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);
});
<!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
}
}
});