AngularDart ng-change

2019-05-11 23:09发布

问题:

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

回答1:

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

a workaround:

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