dimafeng
dimafeng

Reputation: 375

AngularDart ng-change

I have html:

<select ng-model="main.selectedReport" ng-change="main.selectReport()">
                            <option value="">Not selected</option>
                            <option ng-repeat="rep in main.reports" value="{{rep.value1}}">{{rep.value2}}</option>
                        </select>

My controller is:

@NgController(selector: '[main-controller]', publishAs: 'main')
class MainController extends FCViewAbstractController {

  Map reports;
  Long selectedReport;

....

  selectReport() {
    print(selectedReport);
  }
}

My question is why do I get previous selected value in selectReport()? For example: on first selection I got null value.

But version in angularjs works as I expect http://plnkr.co/edit/ILBBWfkRp9tegQZaGZ9u?p=preview

Upvotes: 3

Views: 2608

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657018

Seems to be a known bug ng-change for is invoked before the model is updated #399

a workaround:

  selectReport() {
    new Future(() => print(selectedReport));
  }

Upvotes: 6

Related Questions