I want to call the JavaScript function JSONToCSVConvertor() that is present in function.js file which is same directory in which the below dart file(app_component.dart) is present. I am using the dependency js: ^0.6.0 and I have added that in pubspec.yaml as well. I am not sure as to how to call that JavaScript function from dart file using annotations. Please let me know if the statements in line 1,2 are correct and also how to call the JS function from dart.
Code: 1) app_component.dart
@JS('function')
library function.js;
import 'package:angular/angular.dart';
import 'dart:convert';
import 'package:js/js.dart';
@Component(
selector: 'app-component',
templateUrl: 'app_component.html',
)
class AppComponent {
var name = 'Excel Generation';
@JS("function.JSONToCSVConvertor")
external void JSONToCSVConvertor(jsonvalue,Title);
showData(){
var jsonData = [{"Vehicle":"BMW","Date":"30, Jul 2013 09:24 AM","Location":"Hauz Kh"}];
var jsonvalue = json.encode(jsonData);
String Title = "Excel project";
JSONToCSVConvertor(jsonvalue,Title);
}
}
JSONToCSVConvertor. Do you load the script using a<script type="text/javascript" src="function.js">? Where do you have the script tag and how exactly does it look like.