1

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); } }

1
  • Can you please add at least the signature of 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. Commented Nov 13, 2018 at 6:35

1 Answer 1

1

I think this introduces the function prefix twice

@JS('function')
library function.js;
...
@JS("function.JSONToCSVConvertor")
   external void JSONToCSVConvertor(jsonvalue,Title);

https://pub.dartlang.org/packages/js shows some examples how to do it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.