I am using typescript 1.8 + angularjs v.1.5.8
I have a directive that I want to call like this:
<div mi-directiva mi-parametro="ctrl.Objeto"> </div>
My directive is declared like this:
export class miDirectiva implements ng.IDirective{
restrict:'A';
templateUrl = '/views/template.url';
controller = 'miController';
controllerAs = 'ctrl';
bindToController = true;
scope:{
miParametro:'='
}
constructor(){}
static factory(): ng.IDirectiveFactory {
const directive = () => new miDirectiva();
return directive;
}
}
var app=angular.module('App');
app.directive('miDirectiva',[miDirectiva.factory()]);
My controller is declared like this
export class miController{
miParametro:any;
constructor(scope:any){
var x = scope.miParametro;//undefined
var y = this.miParametro; //undefined
//Como tengo acceso a miParametro?????
}
}
var app=angular.module('App');
app.controller('miController',['$scope', miController]);
Facts:
- myParameter is an object
- From what I've read, I don't need the $link or $compile function, this isn't necessary since I'm declaring that
bindToController=true
and myParameter should already be there available in the controller - If I receive the object
$attrs
in the controller if I can get the object through$scope.$eval($attrs.miParametro)
but something tells me that this is not done like this
How do I access myParameter?
I'm done: https://stackoverflow.com/a/33322500/3596441
I moved the scope definition to
bindToController
and it worked, it'smiParametero
already available atmiController