Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Isolate scope binding to parent function inconsistent context #8552

Closed
@pocesar

Description

@pocesar

When using an isolated scope, I find myself having to return a bound function from a & isolated scope binding, or the this becomes undefined or Window DOM.

    <div ng-controller="MyCtrl as mycontroller">
      <div some-directive="mycontroller.func"></div>
      <div ng-click="mycontroller.func()">Regular ngClick</div>
    </div>
.controller('MyCtrl', function(){
   this.func = function(){ console.log(this); };
})
.directive('someDirective', function(){
  return {
    restrict: 'A',
    scope: { 'fn': '&someDirective' }
    link: function(scope){
       scope.doh = function(){
         scope.fn()();
       };
    }    
  };
});

http://plnkr.co/edit/Dnhd67JxAnbcG9i21b3a?p=preview

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions