This is really just a shorthand for:
- Creating an Angular controller using standard object notation.
- Less repetition, but full support, of dependencies.
- Support either
Controller as resource
, or passing it off to a separate view. - Creating States for ui-route, with all of the above.
What I like about this combined with ui-route is the pattern for resources:
var UIView = require('base/uiview');
var BaseController = require('base/controllers');
require('resource/services');
var base = {
abstract: true,
// The name for inheritance
name: 'resource',
// The base URL for the views
url: 'resource',
// Inherit from the very base controller.
parent: BaseController.base,
template: '<ui-view></ui-view>'
};
var list = UIView.extend({
url: '',
name: 'resource.list',
define: 'ResourceList',
as: 'resource',
parent: base,
templateUrl: 'partials/resource/list.html',
// Since we are injecting the Simulations Service
// (combined with UIView.extend and `Controller as` syntax),
// the template gets access to `this.ResourceService` automatically.
//template: '<div ng-repeat="obj in resource.ResourceService.all()">{{ obj.title }}</div>',
inject: ['$scope', 'ResourceService']
});
var details = UIView.extend({
url: '/:id',
name: 'resource.details',
define: 'ResourceDetails',
as: 'resource',
parent: base,
templateUrl: 'partials/resource/details.html',
inject: ['$scope', '$stateParams', 'ResourceService'],
initialize: function () {
this.obj = this.ResourceService.get(this.$stateParams.id);
}
});
module.exports.base = base;
module.exports.list = list;
module.exports.details = details;