I have been exploring a way to attach the controller object to the scope in a different manner. Here is an example of how it can be achieved.
interface IAppCtrlScope extends ng.IScope {
info: any;
}
class InfoCtrl {
header: string;
name: string;
public static $inject = ["$scope"];
constructor(private $scope: IAppCtrlScope) {
this.$scope.info= this; //expose controller
}
getData(): void {
//perform some actions
}
}
When implementing this, the view HTML code would look like the following:
<div ng-controller="InfoCtrl">
<div class="rm-dialog-header">{{info.header}}</div>
<span ng-click="info.getData()">{{info.name}}</span>
</div>
However, I am curious if there is a way to simplify the controllers' exposure so that I don't need to use 'info.' prefix for each scope variable. This would result in a cleaner view structure like this:
<div ng-controller="InfoCtrl">
<div class="rm-dialog-header">{{header}}</div>
<span ng-click="getData()">{{name}}</span>
</div>
I am wondering if there is a way to achieve this or if I might have overlooked something in my approach.