4

This is my HTML Cod

<ion-view view-title="Home" ng-controller="makeOrderController">
    <input type="search" placeholder="Tìm kiếm" ng-model="searchKeyword" ng-change="searchMenu()" >
</ion-view>

This is my JS code

....
.controller('makeOrderController', ['$scope', function ($scope) {

    $scope.searchMenu = function ($scope) {
        console.log($scope.searchKeyword);
    }

}]);

Yeah. When i type on the search textbox, the searchMenu() method is executed, but it raised an error

Cannot read property 'searchKeyword' of undefined

I have searched on SO, I tried :

  • To add $parent. to ng-model

  • Or use js statement is $scope.model.searchKeyword. But these code are not work :(

Please help me to help the console.log write updated keyword on user type.

2
  • You should use JSLint or JSHint to run through your code; if you use the yeoman ionic-generator module, it's built in. This would catch those sort of errors. Commented Aug 6, 2015 at 17:34
  • Oh, I didn't know about this. I will try to explore it :D Many thanks :) Commented Aug 6, 2015 at 18:13

1 Answer 1

6

You have 2 $scope variables. So the inner most $scope is taking the preference which is undefined.

Get rid of that..

.controller('makeOrderController', ['$scope', function ($scope) {

    $scope.searchMenu = function () {
        console.log($scope.searchKeyword);
    }

}]);

Fiddle

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.