AngularDart: 'nGBootstrap is not defined' error - dart

I'm trying to run this simple code from here
import 'package:angular/angular.dart';
void main() {
ngBootstrap();
}
But i recieve this error:
The function 'ngBootstrap' is not defined
Any idea about what's happening? I already tried 'pub get'.

Lastest angular version is 0.9.11.
So, you must use ngDynamicApp().addModule(new MyAppModule()).run(); instead of ngBootstrap(module: new MyAppModule());, and add import 'package:angular/angular_dynamic.dart'; in your main.dart.

Lastest angular version is 0.10.0.
So, now you must use applicationFactory().addModule(new MyAppModule()).run(); instead of ngDynamicApp().addModule(new MyAppModule()).run();,
and always add import 'package:angular/angular_dynamic.dart'; in your main.dart.
Be careful, many thing has changed, like we use Component without #... etc.

Related

how can i import main functin of another dart file

How can I verify that a print is called for in dart unit tests?
I am writing a sample code for textbooks and want to try it out. There are many examples that use printing for simplicity. I want to run my unit tests to make sure the print is called with the correct input but I have a problem importing the main function in another dart file.
Thank you!
You can import any library, including a script with a main method. The problem is that your own script's main method shadows the import.
The solution is to import the library with a prefix:
import "other_library.dart" as testee;
void main() {
print("Testing something");
testee.main(); // Uses a prefixed name to avoid name conflict.
print("Testing done");
}

Angular 4+ 3rd party module import 404 error with base tag

I am putting an angular portion into my MVC app. As such, I have added a tag to my layout view to find the Angular source code, and this is working great.
My issue arises in trying to add a 3rd party module to my project. I added it through the package.json with no problem, and added the module to my app.module.ts as follows:
import { FileUploadModule } from 'primeng/fileupload';
The reference is found, Visual Studio is happy, everything is fine. However, when I run the project locally, I get the following 404 error:
GET http://localhost:59911/src/primeng/fileupload 404 (Not Found)
It seems to me likely that the tag is causing the issue, but I can't remove it without killing the rest of the Angular functionality. Any hints? Can I add an override to the imports call?
Thanks, Mike
On PrimeNG's official website they suggested using import { FileUploadModule } from 'primeng/fileupload'; but it doesn't work any more. I guess they didn't update the docs.
You need { FileUploadModule } from 'primeng/primeng';
The structure is
In the primeng.d.ts file PrimeNG re-exported all modules.
export * from './components/fileupload/fileupload';
For now, no matter which PrimeNG module is used, it is all from primeng/primeng. Here's the imported modules in my project:
import {
ButtonModule,
CodeHighlighterModule,
ConfirmDialogModule,
FieldsetModule,
FileUploadModule,
GrowlModule,
MessagesModule
} from 'primeng/primeng';
The version I use is "primeng": "^4.2.1"
The issue was that primeng was not in the mapping, so it was looking for it in src.
I added the following to systemjs.config.js:
in maps:
'primeng': 'npm:primeng',
in packages:
primeng: {
defaultExtension: 'js'
}
Thanks for the help everyone!

how to start an angular.dart app

I am on angulardart 0.11.0 and this is my code for main.dart:
library my_app_main;
import 'package:angular/angular.dart';
import 'package:angular/application_factory.dart';
import 'package:my_app/src/something.dart';
class MyModule extends Module {
MyModule() {
bind(MyAppCtrl);
bind(MyComp);
}
}
main() {
applicationFactory()
.addModule(new MyModule())
.run();
}
I get syntactic errors:
angular.dart import is 'unused'
'Module' is an 'undefined class'
I have tried deleting and rebuilding the packages directory, pubspec file, etc. What is going on?
angular.dart import is 'unused' is just a warning, so you don't really need to worry about it.
You're seeing 'Module' is an 'undefined class' because you're not importing the di library. Add
import 'package:di/di.dart'; to your imports and it should run.
Turns out the error was caused by the angular files becoming corrupted in the pub cache. As was pointed out here (https://groups.google.com/forum/#!topic/angular-dart/WiZuIwxTDb4) - thanks Günter! - the solution is to repair the pub cache by doing 'pub cache repair' or at least 'pub cache add angular'

Using thirdparty libraries from dart language

How can import and use any third party javascript libraries in dart..? I want to use snapsvg in my dart application to render svg. But not sure how to add dependencies to add and import it.
I added js: any to my pubspec.yaml and imported packages/browser/interop.js into my html. Where do I place downloaded snapsvg.js and import it to my dart source file to use it.
I am trying to use following javascript code using snapsvg framework from dart.
s = Snap(800, 600);
s.rect(0, 0, 100, 100).attr({
fill: 'white',
stroke: 'black'
});
I tried this code from in dart:
import 'package:js/js.dart' as js;
void main() {
var s = js.context.Snap(800, 600);
s.rect(0, 0, 100, 100);
}
This works fine in dartium, but when I Run as Javascript after build, I got javascript error "method zm not found in object"
I believe this is not right way and I should use be using callMethod on proxy. So I changed code like this
import 'dart:js' show context, JsObject;
void main() {
var snap = context['Snap'];
snap.callMethod('rect', 0,0,100,100);
}
This is not working in Dartium as itself. I would appreciate if someone can provide example of how to call constructor Snap(800, 600) from dart and also rect and attr methods in my example code.
You add them to the HTML file using <script> tags.
You can call JavaScript functions from Dart using dart-js-interop.
There are many examples here on Stackoverflow under this tag - just click on the tag below your question.
When you provide a more concrete example it is easier to help.
You can call into JavaScript with the built-in dart:js library. Please try to avoid using /package/ js, which is what you install by adding js: any to your pubspec. The js package is likely to cause the dart2js output to be bloated and we're probably going to deprecate it at some point.
You can reference JavaScript files like you would in any HTML page, via script tags. You don't actually import them into Dart source, you use dart:js to access JavaScript via its top-level context property.

Could not find class 'weka.core.FastVector',

I am using weka for my project. but get the error info"could not find class weka.core.FastVector" on the line below. I have already added weka.jar from the build path of the project by adding external jar file. How should I solve this problem? Thanks a lot for your time on reviewing my question.
import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instance;
import weka.core.Instances;
FastVector atts;
private void setUpARFF(){
atts = new FastVector();}
I know that FastVector was marked as obsolete a while back, perhaps they've finally removed it. Are you using the dev version of weka (or what version are you using)? FastVector can be replaced with ArrayList (in dev version) so use that instead.

Resources