2

Facing a weird issue, where a simple text field value is not getting printed when using tabset. Wrote a sample to demo the same. Please check it below link

sample link

<tabset>
    <tab heading="Static title">Testing input
    <input ng-model="nameStr" value="">
    <button class="btn btn-default btn-lg " type="button" ng-click="callMe()" >Test callme</button>
    </tab>
    <tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disabled="tab.disabled">
      {{tab.content}}
    </tab>
    <tab select="alertMe()">
      <tab-heading>
        <i class="glyphicon glyphicon-bell"></i> Alert!
      </tab-heading>
      I've got an HTML heading, and a select callback. Pretty cool!
    </tab>
  </tabset>

Do suggest, what would have been missed out.

Thanks in advance.

1
  • 1
    what exactly is the problem? Commented Apr 15, 2015 at 19:17

2 Answers 2

3

There is some questions about angular-ui way of encapsulate controllers inside it's directives (the idea is to have different controllers for different tasks). The problem, to access your "original" controller (and not the ones in the ui-bootstrap directive) you have to use the $parent in your view. Because the current $scope inside tabset is pointing to another controller.

So, it will become

<input ng-model="$parent.nameStr" value="">

I couldn't find the right explanation in the angular-ui repo, but this seems to get some ideas.

https://github.com/angular-ui/bootstrap/issues/2971

Older Answer

You can replace the $scope.nameStr inside the $scope.callMe for this.nameStr.

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

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

6 Comments

But can you explain the behavior? the nameStr is not in the scope if you try to dump $scope to console.. it is also not available on parent.. but how "this"?
lol, I know, is little be confused, I'll explain better.. and offer the recommended way for this.
Thank you for the help. I do get what it mean but may be missing the actual theory. If possble, hint me.
this solved part of the issue for me, now I have a $scope variable in Controller gets updated in service call and I can't access that value. Any idea on how to solve that
@user1686758 I updated the answer, try using the new approach, because the this is the first way that I used to do this. Take carefully with the this, because inside anonymous functions it will have another scope.
|
1

My solution:

$scope.name = {};
$scope.callMe = function(){
  alert('title ->'+$scope.name.str);
}

In html:

<input ng-model="name.str" value="">

Angular works much better this way. Using dot properties.

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.