I want to provide a set of access controllers to the methods and properties defined in the attribute. Right now, the best implementation I came up with is this:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, CtrlTrait) {
$scope.name = CtrlTrait.presetName;
CtrlTrait.setGreeting.call($scope, 'Hello');
});
app.service('CtrlTrait', function() {
this.setGreeting = function(greeting) { this.greeting = greeting; }
this.presetName = 'tom';
});
Plunkr Code
This is good, but I would like the properties and method to be accessible through the $ scope control area without the need to manually create an alias in each controller. I want to be able to use the properties and method from the template by simply inserting the service into the controller.
Is this possible, or do I need to create a [wrapper around] / [provider for] $scope, for example $specialCtrlScope, that sets the properties and methods that I want?
source
share