dart-js-interop

Difference between Dartium and dart2js when building chrome extensions

最后都变了- 提交于 2019-12-23 03:22:38
问题 I have the following problem when running dart2js compiled version of my chrome extension: Uncaught TypeError: Object #<JsObject> has no method 'where$1' I have created a minimal example: background.dart import 'dart:js'; void main() { print("main()..."); context['js_list'] = new JsObject.jsify(["aaa", "bbb"]); } popup.dart import 'dart:js'; var backgroundPage = context["chrome"]["extension"].callMethod("getBackgroundPage", []); void main() { print("main():..."); testJsList(backgroundPage['js

How to map a Dart class to a JS “class” with the new js 0.6.0 package?

南笙酒味 提交于 2019-12-21 21:00:29
问题 index.html <!doctype html> <html> <head> </head> <script> var Apple = function(type) { this.type = type; this.color = "red"; }; Apple.prototype.getInfo = function() { return this.color + ' ' + this.type + ' apple'; }; </script> <body> <script type="application/dart" src="index.dart"></script> <script src="packages/browser/dart.js"></script> </body> </html> index.dart import 'dart:js' as js; import 'dart:html' as dom; import 'package:js/js.dart'; main() { // this works fine var apple = new js

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

感情迁移 提交于 2019-12-20 02:52:41
问题 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

Using dart to create a javascript library

a 夏天 提交于 2019-12-19 07:50:31
问题 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:

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

有些话、适合烂在心里 提交于 2019-12-18 05:15:10
问题 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

How to call a jQuery function from Dart?

白昼怎懂夜的黑 提交于 2019-12-18 04:45:10
问题 This is a typical situation in jQuery: $(".myClass").myFunction({ aKey: 'some value' }); How do you call that using dart:js? The documentation is a bit cryptic and a similar question that I found here seems dated. 回答1: You can do : main() { js.context.callMethod(r'$', ['.myClass']) .callMethod('myFunction', [new js.JsObject.jsify({'aKey': 'some value'})]); } 回答2: You can use the build-in funcitons querySelector or querySelectorAll instead of the jQuery selector. So it would be: main(){

Expose Dart functions to javascript

天涯浪子 提交于 2019-12-17 16:09:42
问题 I'm a bit of a newb to dart, and trying to get my feet wet by writing some library functions in it. While I've had no problem calling javascript functions from dart, I'd love to be able to call dart functions from javascript, but so far, I'm not having much like. For example, I'd love to be able to expose some basic functions from dart, for example like so: main() { String foo() { return "bar!"; } js.scoped(() { js.context.foo = foo; }); } and then be able to call them from javascript, like

Getting an arbitrary property from a JavaScript object in Dart

白昼怎懂夜的黑 提交于 2019-12-14 02:05:17
问题 Edit: Here is a minimal project that illustrates my issue. You can see the error described by serving it to the browser: pub get and then either pub serve (dartium) or pub build --mode=debug (other browsers). How can I access an arbitrary JavaScript property from Dart through a JsObjectImpl? I am using the ace.js library with an interop to Dart that I've adapted from a typescript interface, and the method I am calling returns a plain javascript object with key-value pairs. Dart gives me a

How do I create a global (on the window) object in Dart lang?

≡放荡痞女 提交于 2019-12-14 01:40:18
问题 Let's say I want to create a global object called Hello and add the function world on that object, so that any other JavaScript library in the browser can simply call it with window.Hello.world(); How do I create such an object in Dart lang and how do I expose it / place it globally / on the window object? In plain JavaScript, I would be able to write: window.Hello = { world: function() { console.log("Hello World!"); } } window.Hello.world(); But how do you do this in Dart? 回答1: I work on

Dart chrome extension: Listen to chrome api events

£可爱£侵袭症+ 提交于 2019-12-13 14:41:34
问题 To better describe my problem i have created a small example of a chrome extension written in Dart. You can see the code or download the extension on Gist. The problem This example is running fine in Dartium, but when compiled to javascript a typeerror occurs: Uncaught TypeError: undefined is not a function for the line: context['chrome']['runtime']['onMessage'].callMethod('addListener', [onMessageListener]); How far i already am As you may see in the example the functions alert() or console