3

I m actually creating a little directive and I m facing a problem with the scope object and controllAs.

In fact, I have this result :

angular.module('app')
.directive('historyConnection', function () {


  return {
    templateUrl: 'views/directives/historyconnection.html',
    restrict: 'E',
    scope: {
      idUser: '@iduser'
    },
    controller:function($scope){
      console.log(this.idUser); // gives undefined
      console.log($scope.idUser); // gives the good value
    },
    controllerAs:'history'
  };
});

From the html code :

<history-connection iduser="55"></history-connection>

I dont know how to make controllerAs work when passing parameters to directive. Can you help me ?

Important informations are commented in the javascript code above

3

1 Answer 1

3

If you want the scope properties to be bound to the controller you have to add bindToController: true to the directive definition.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.