dart-js-interop

how to call a jquery plugin from inside an angular.dart component?

橙三吉。 提交于 2019-12-02 01:41:42
I am learning about angular.dart components by trying to make one that will access an existing jquery plugin. I am trying something like the following: library mylib; import 'dart:html'; // querySelector import 'package:js/js.dart'; // javascript import 'package:angular/angular.dart'; @NgComponent( selector: 'aSelector', templateUrl: 'partial.html', cssUrl: 'style.css', publishAs: 'ctrl', map: const { 'param': '=>param' } ) class myComponent extends NgShadowRootAware { String param; Compiler compiler; Injector injector; Scope scope; MyComponent(this.compiler, this.injector, this.scope); void

How do I create an anonymous JavaScript function/callback with Dart's JS interop?

倾然丶 夕夏残阳落幕 提交于 2019-12-01 19:03:05
I am using Dart and its JS interop . I need to convert the following JavaScript code to Dart: ID3.loadTags("filename.mp3", function() { var tags = ID3.getAllTags("filename.mp3"); if (tags.artist) artist.textContent = tags.artist; if (tags.title) track.textContent = tags.title; }, { dataReader: FileAPIReader(file) }); Note the anonymous callback as the second parameter to loadTags . How do I create that with Dart and the dart:js library? The closest I got was creating a named function with: js.context['loadTagsCallback'] = () { var tags = ID3.callMethod('getAllTags', ["filename.mp3"]); var

How to call a dart method from Javascript after dart2js

可紊 提交于 2019-12-01 11:15:22
I got this Dart Script below and I want to access the methods from the class hello_world by JavaScript after I compiled the Dart Script with dart2js. Does anybody know how this works?! I already know how to access the functions like foo(...), thats not the problem, but it does not work the same way with classes and methods. And the tutorials on dartlang.org only explain how to access functions, not methods and classes. I dont get it... import 'dart:js' as js; class hello_world { String hello = 'Hello World!'; String getHello() { print("getHello!!!!!"); return hello; } void ausgabe() { print(

Using Dart classes from JavaScript

為{幸葍}努か 提交于 2019-12-01 10:41:25
I have a Dart class (foo.dart): class Foo { void talk() { print('Hello'); } } After compiling foo.dart to JavaScript, I'd like to be able to use Foo like this: var foo = new Foo(); // from foo.dart.js foo.talk() // prints "Hello" My questions: Is this currently possible? If so, how? If not, what plans, if any, are in place to make it possible? The dart:js library documentation states : This library does not yet make Dart objects usable from JavaScript, their methods and proeprties [sic] are not accessible, though it does allow Dart functions to be passed into and called from JavaScript. That

How to call a dart method from Javascript after dart2js

只谈情不闲聊 提交于 2019-12-01 08:50:28
问题 I got this Dart Script below and I want to access the methods from the class hello_world by JavaScript after I compiled the Dart Script with dart2js. Does anybody know how this works?! I already know how to access the functions like foo(...), thats not the problem, but it does not work the same way with classes and methods. And the tutorials on dartlang.org only explain how to access functions, not methods and classes. I dont get it... import 'dart:js' as js; class hello_world { String hello

Using dart to create a javascript library

早过忘川 提交于 2019-12-01 06:07:02
The problem I'm currently working on a JavaScript library, and in order to reduce the amount of bugs I thought that my library might benefit from using Dart's static typing mechanism. First, because my lib wasn't doing any interop neither with HTML nor with other JavaScript libraries, only pure javascript object manipulation stuff. However I didn't find any info on the net showing how it is possible to build a JS library using dart. So I've tried to do that myself, created initial dart file: library Repo; class Type { final String name; final TypeCategory category; Type(String name,

What is a difference between dart:js and js package?

大兔子大兔子 提交于 2019-12-01 03:09:50
Everywhere in Dart documentation it is recommended to use js package for javascript interoperability. However, I have recently found that dart:js package exists in SDK that seems to have similar (but not same) interface. Are there any differences between these packages? Are they feature equivalent? Which one is recommended? Js interop started with package:js . It was built with with window.postMessage . Later dart:js has been added to provide better performance and reduce the size of the compiled js file. Basically the goal were : removing scopes and lifecycle manual handling avoiding

Is there a better way to make a method of a Dart class callable from JS with the new js 0.6.0 package?

大兔子大兔子 提交于 2019-11-30 13:57:51
index.html (head) <script> var callDartMethod = function(dartObject) { return dartObject.fullName(); } </script> index.dart import 'package:js/js.dart'; @Js() // about to being changed to @JS external String callDartMethod(p); main() { final p = Person.create(firstName: 'Günter', lastName: 'Zöchbauer'); print(callDartMethod(p)); // indirect call from JS // print(p.fullName()); // call from Dart directly } @Js() // about to being changed to @JS class Person { external String get firstName; external set firstName(String firstName); external String get lastName; external set lastName(String

js interop compiled with dart2js error - Uncaught NoSuchMethodError : method not found:

你。 提交于 2019-11-29 08:20:56
I generated a sample Polymer web project. Added following js file. jslib.js function testfunction() { alert("test"); } in clickcounter.dart I added dependency import 'package:js/js.dart' as js; and changed increment() function void increment() { js.context.testfunction(); count++; } In clickcounter.html added js file import <script src="jslib.js" type="text/javascript"></script> And in main html file added <script src="packages/browser/interop.js"></script> It works correctly when in executed in Dartium. When I compile it to javascript however it gives an error Uncaught NoSuchMethodError :