-2

I have found this solution and I'm trying to use it by ES6 but in controller, search function which looks like this (just beginning)

customSearch(item){ console.log(this.$scope); returns TypeError: Cannot read property '$scope' of undefined

Community
  • 1
  • 1
Przemek
  • 27
  • 3

1 Answers1

0

We might need to see more of your code, but if you're trying to implement an angular controller as an ES6 class, you need to pass your dependencies into the class constructor.

class SearchCtrl {
    constructor($scope) {
        this.$scope = $scope;
    }

    customSearch(item) {
        console.log(this.$scope);
    }
}

angular.module("app").controller("SearchCtrl", SearchCtrl);
Shaun
  • 2,012
  • 20
  • 44