Compiled AngularDart fails with error in dynamic_injector - dart

I have been trying to make AngularDart work but I always get exceptions for undefined objects.
#MirrorsUsed(
targets: const [
'angular.core',
'angular.core.dom',
'angular.core.parser',
'angular.routing',
'angular.core.zone',
'di.di',
'di.dynamic_injector',
NodeTreeSanitizer,
DynamicParser,
DynamicParserBackend,
Injector
],
metaTargets: const [
NgInjectableService,
NgComponent,
NgDirective,
NgController,
NgFilter,
NgAttr,
NgOneWay,
NgOneWayOneTime,
NgTwoWay,
NgCallback,
NgZone
],
override: '*'
)
import 'dart:mirrors';
And compiled javascript showing error:
Uncaught TypeError: Cannot call method 'get$parameters' of undefined dynamic_injector.dart:42
DynamicInjector.newInstanceOf$4 dynamic_injector.dart:42
When I'm removing MirrorsUsed2 there is no errors, but compiled file is large.

Adding these helped for me
'angular.filter',
'angular.perf',
'perf_api',
and instead of angular.core.parser
'angular.core.parser.dynamic_parser'
'angular.core.parser.lexer'
I also added all my own libraries.
See also https://code.google.com/p/dart/issues/detail?id=14686

Recently, I found Dart-AngularJS when compiled not to run, even the simplest example. I reinstalled my dart sdk to the latest stable version and the errors disappeared. Could you see if this works? Please see related issue on github project.

Related

What is the purpose of foundation.dart in Writing and Reading Files using path_provider plugin?

I am trying to understand how to read and write data on text files using path_provider plugin.
I've read an example on how to use it on Flutter from here. Then I saw this line of code which I don't understand:
import "package:flutter/foundation.dart";
I tried to comment it out from the code and ran "flutter run":
//import "package:flutter/foundation.dart";
And to my surprise, it ran perfectly. Although it raised some errors like:
E/DartVM (23127): 'dart:core/runtime/libintegers.dart': error: Unexpected tag 0 (Nothing) in ?, expected expression
E/DartVM (23127): ../../third_party/dart/runtime/vm/compiler/intrinsifier.cc: 153: error: Intrinsifier failed to find method ~ in class _Smi
and
E/DartVM (23237): 'dart:typed_data': error: Unexpected tag 15 (DirectPropertyGet) in ?, expected type
E/DartVM (23237): ../../third_party/dart/runtime/vm/compiler/intrinsifier.cc: 153: error: Intrinsifier failed to find method get:x in class _Float32x4
But it ran well. I don't know why. When should I use it? What method from the code did the foundation.dart was used?
I would appreciate any kind of enlightment. Thanks in advance.
[UPDATE]
I think I understand why foundation library was used in the example code. Maybe because the example code used the "required" constant from the foundation library.

When i try to use ng-select2/ng2-select/ng2-select2 with angular 5 project #types/select2 package gives a error

ERROR in node_modules/#types/select2/index.d.ts(163,18): error TS2430: Interface 'AjaxOptions' incorrectly extends interface 'Pick string)' is not assignable to type 'string'.
Type '(params: QueryOptions) => string' is not assignable to type 'string'.
After reasearching a lot and trying to find a solution on my own (due to lack of solutions on internet), I found a fix at least for my issue.
I will share it with you just in case.
On my case the root cause of this was an entry on '.angular-cli.json' that was missing and because of this the 'select2' js file was not being uploaded.
So I just added this line to the .angular-cli.json:
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/jqueryui/jquery-ui.js",
"../node_modules/select2/dist/js/select2.full.js",
This solved my issue and now I'm able to use the select2 control.
Note that you might need to add the .css for select2 as well ;).
Good luck!.

What Is the Replacement for the #Decorator Directive?

I'm upgrading my dart code from angular 1 to angular 4.
This line now gives an error in my IDE:
#Decorator(selector: '[citable]')
Annotation must either be a const variable or const construction invocation.
I was able to fix this error on #Input by including the formDirective. What directive should I use for #Decoration? I can't find any recent mention of #Decorator in a web search for AngularDart.
I tried adding const after selector:. Then I get a syntax error.
The replacement is #Directive.

Code from dart2js is throwing NoSuchMethodErrors for get$functions

My Polymer.dart web app, that works fine in Dartium, is giving the following error (it repeats seven times) when compiled with dart2js using pub build --mode=debug and loaded in Chrome.
Resource interpreted as Script but transferred with MIME type text/plain: "http://confab.dev/index.html_bootstrap.dart". confab.dev/:10
warning: file:///home/dan/projects/confabulous/webatara/web/index.html.0.dart library not found index.html_bootstrap.dart.js:17188
Uncaught Error: NoSuchMethodError: Cannot call "get$functions" on "#<JsLibraryMirror>" (Object #<JsLibraryMirror> has no method 'get$functions') index.html_bootstrap.dart.js:17188
Stack Trace:
TypeError: Object #<JsLibraryMirror> has no method 'get$functions'
at dart._loadLibrary (http://confab.dev/index.html_bootstrap.dart.js:20000:19)
at dart._loadLibraries (http://confab.dev/index.html_bootstrap.dart.js:19917:11)
at dart._initPolymerOptimized (http://confab.dev/index.html_bootstrap.dart.js:19908:7)
at dart.initPolymer (http://confab.dev/index.html_bootstrap.dart.js:19902:7)
at main (http://confab.dev/index.html_bootstrap.dart.js:4112:7)
at _IsolateContext.eval$1 (http://confab.dev/index.html_bootstrap.dart.js:1369:23)
at dart.startRootIsolate (http://confab.dev/index.html_bootstrap.dart.js:1145:21)
at http://confab.dev/index.html_bootstrap.dart.js:26514:7
at init.currentScript (http://confab.dev/index.html_bootstrap.dart.js:26494:5)
at http://confab.dev/index.html_bootstrap.dart.js:26508:3
index.html_bootstrap.dart.js:17188
Uncaught NoSuchMethodError: Cannot call "get$functions" on "#<JsLibraryMirror>" (Object #<JsLibraryMirror> has no method 'get$functions') index.html_bootstrap.dart.js:2369
Because source maps don't appear to work (they're turned on in Chrome, and I have .map files), I don't even know which part of my code is causing this.
I've tried with interop.js included both before dart.js, as the docs say, and after, as this issue says.
Looks like a bug in dart2js. Please file an issue, ideally with a reproducible test-case.
pub upgrade fixed it. It turns out that something had replaced the polymer 0.9.5 that I'd been using with 0.8.10+4. Quite odd. The solution to this is to set the polymer version as '>= 0.9.5' instead of 'any', which I will do eventually, but for now I'm interested to see if it happens again.

Debugging MirrorsUsed

I'm trying to figure out which libraries I need to pass to #MirrorsUsed to get my app compiled and working. Sometimes, it's easy to figure out which library may be missing since a descriptive error is thrown such as Uncaught Unsupported operation: Cannot find class for: NgAttr .
Other times, I get a more obscure message, such as NullError: Cannot call "$gt" on null with no clue as to which library I may be omitting. Is there a better approach to this, besides trial and error?
In case you're wondering, this is an angular app and this is how I currently have it configured:
#MirrorsUsed(targets: const[
'angular',
'angular.core',
'angular.core.dom',
'angular.filter',
'angular.perf',
'angular.directive',
'angular.routing',
'angular.core.parser.dynamic_parser',
'angular.core.parser.lexer',
'todo',
'perf_api',
'List',
'NodeTreeSanitizer',
'PlaybackHttpBackendConfig'
],
override: '*')
import 'dart:mirrors';
Use
pub build --mode=debug
this does tree shaking but retains (mostly) the original Dart names.
Then debugging the generated JavaScript usually lets deduce the source of the exception.
EDIT
IMHO these are not necessary anymore, because they were added to #MirrorsUsed in the Angular libs.
'angular',
'angular.core',
'angular.core.dom',
'angular.filter',
'angular.perf',
'angular.directive',
'angular.routing',
'angular.core.parser.dynamic_parser',
'angular.core.parser.lexer',

Resources