Censin DO
Censin DO

Reputation: 1

Ionic v1 ng-model doesn't update

This is my HTML structure in Ionic project.

<div ng-model="pollPage.test.username">updated content</div>
{{pollPage.test.username}}

Controller:

  vm.test = {
        username : 'static',
  }

When I use check my page, its getting 'static' text however it should be 'updated content'

Whats the problem? I guess everything is right but its not working. Thanks.

Upvotes: 0

Views: 523

Answers (2)

Sletheren
Sletheren

Reputation: 2486

ng-model should be on an element that its content changes like: input, select, textarea...etc

Upvotes: 0

Jesus Carrasco
Jesus Carrasco

Reputation: 1354

Your code is wrong it shoulbe like this:

<div ng-controller="yourController as vm">    
    <input type="text" ng-model="vm.pollPage.test.username">
    <div>{{pollPage.test.username}}</div>
</div>

You cant asign ng-model to a div it must be on elements I/0 like inputs, dropdowns, checks, etc.

Controller:

 var vm = this;

  vm.pollPage = {};
  vm.pollPate.test = {
    username : 'static',
  }

Upvotes: 1

Related Questions