Search code examples
angular-dart

I can not access it from any list element method (Invalid argument (index): "2") in Angular dart


@Component(
  selector: 'my-app',   
  template: '''  <div> <button (click)="getItemName(2)"> get</button> </div>    ''',
) 
class ListComponent {  //...
  List<Product> listProducts;

  void getItemName(int id) {
    print(listProducts[id].name); // <- invalid argumant (index) : "2"
  } 
} 

html_dart2js.dart:3558 EXCEPTION: Invalid argument (index): "0" STACKTRACE: Invalid argument (index): "0" at Object.wrapException (http://127.0.0.1:8092/main.dart.js:4242:17) at Interceptor.$index (http://127.0.0.1:8092/main.dart.js:1082:19) at Object.J.$index$asx (http://127.0.0.1:8092/main.dart.js:102985:43) at GroupsComponent.add$1 (http://127.0.0.1:8092/main.dart.js:45152:46) at Object.J.add$1$ax (http://127.0.0.1:8092/main.dart.js:103054:42) at ViewGroupsComponent0.dart.ViewGroupsComponent0._handle_click_131_0$1

where do i make mistakes thanks


Solution

  • The index parameter needs to be an integer value, not a string.