1

I find it a bit weird about the problem i am facing. here it is.

HTML

<div>
     <select ng-model="params.select" ng-change="View($event)">
           <option value="" disabled>-</option>
           <option value="table1">Table 1</option>
           <option value="table2">Table 2</option>
           <option value="table3">Table 3</option>
     </select>
</div>     

Controller

$scope.View = function ($event) {
  if($scope.params.select =='table1') {
     console.log('table 1 is selected');
  }

In the above code, if i check whether the dropdown value is table1, i am able to check that. this works fine.

However, if i try to initialize it. for e.g.

$scope.params.select = 'table1'

It gives an error in the console view stating 'Cannot set property 'select' of undefined. Can someone highlight me please where i am going wrong.

1 Answer 1

1

Make sure $scope.params is defined and an object:

$scope.params = {}
$scope.params.select = 'table1'

or define and set all at once:

$scope.params = {select: 'table1'}
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.