0

I have the following tabset and controller:

<tabset>
  <tab>
     <tab-heading>test</tab-heading>
     <div>
        <input type="text" class="form-control" data-ng-model="searchValue" data-ng-enter="search()" />
     </div>    
  </tab>
  <tab>...</tab>
</tabset>


app.controller('MyController', function($scope) {
   $scope.search = function() {
       var param = $scope.searchValue;
       //param is undefined
   };
}

In the above, $scope.searchValue is always undefined. I know this has something to do with the scope since if I remove the tabset, it works fine. I have seen other simliar posts that suggest adding an empty object to the controller, such as: $scope.searchValue = {}; I tried adding $scope.searchValue = '' but this did not resolve my issue. Whats the solution? Thanks.

1
  • Can you post more of your code in a JSFiddle? Are you defining the app and the controller properly in the HTML? Does the function definitely get called (i.e. do you have some console.log() output somewhere in it?) when you hit enter? Commented Aug 15, 2014 at 14:27

1 Answer 1

1

You should try using a dot. Like this:

<input type="text" ng-model="data.searchValue" />

app.controller('MyController', function($scope) {
    $scope.data.searchValue = 'test';
});

Because if a new scope is created, the variable might get replaced instead of updated.

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

2 Comments

Thanks, this worked, however I don't quite understand you're explanation.
It is better explained here. Apparently the golden rule of AngularJS is to always use a . with ngModel.

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.