我无法从Angular dart中的任何列表元素方法(无效参数(索引):" 2")访问它

时间:2018-05-03 11:53:17

标签: 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:无效的参数(索引):&#34; 0&#34;   STACKTRACE:无效的参数(索引):&#34; 0&#34;       at Object.wrapException(http://127.0.0.1:8092/main.dart.js:4242:17)       在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)       在ViewGroupsComponent0.dart.ViewGroupsComponent0._handle_click_131_0 $ 1

我在哪里犯错误

1 个答案:

答案 0 :(得分:0)

index参数必须是整数值,而不是字符串。