JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="test" >
<div ng-controller="test">
{{test}}
<button ng-click="logServiceScope()">Log service context</button>
</div>
<div ng-controller="test2 as scope">
{{scope.test}}
</div>
</div>
JavaScript
var app = angular.module('test', [])
.controller('test', function ($scope, test) {
console.log('Controller context', this);
$scope.test = 'Hi guys';
$scope.logServiceScope = function () {
test.test();
}
})
.controller('test2', function () {
this.test = 'hi guys';
})
.service('test', function(){
this.hi = 'huys';
this.test = function () {
console.log('service context', this);
}
});