how to start an angular.dart app - dart

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'

Related

Angular Dart project, why am I seeing error runApp(ng.AppComponentNgFactory)

I am new to Angular Dart. I have installed Dart, and added dart plugin in VS code. Then I created a bare bone project thru VS command pallette. But when I added this line in main.dart, I got build error. It is as recommended by angular dart i.e
angular dart
Here is my main.dart file.
import 'dart:html';
import 'package:angular/angular.dart';
import 'package:angular_web_application/app_component.dart' as ng;
import 'package:http/browser_client.dart';
#GenerateInjector([
ClassProvider(Client, useClass: BrowserClient),
])
void main() {
runApp(ng.AppComponentNgFactory);
}
Here is my app_component.dart
import 'package:angular/angular.dart';
#Component(
selector: 'my-app',
template: '<h1>Hello {{name}}</h1>',
)
class AppComponent {
var name = 'Angular';
}
In my index.html, I have this line
<my-app>Loading</my-app>
But I am facing build error for the line
runApp(ng.AppComponentNgFactory);
I get this error:
"message": "The name 'AppComponentNgFactory' is being referenced through the prefix 'ng', but it isn't defined in any of the libraries imported using that prefix.\nTry correcting the prefix or importing the library that defines 'AppComponentNgFactory'.
The factory is not declared in the app_component.dart.
It is generated by Angular compiler
import 'package:angular_web_application/app_component.template.dart' as ng;
Which should have the right implementation.
See What does somecomponent.template.dart import in AngularDart point to? for example.

Cordova plugin package android.javax.sip does not exist

I want to build a Cordova plugin for Ionic app, and this plugin I think I have already imported the library (here is the java code, as you can see I write the import statement)
package session;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
import android.Manifest;
import android.os.Handler;
import android.javax.sip.Dialog;
import java.lang.ref.WeakReference;
public class MediaSipSession extends CordovaPlugin{
private static String TAG = "MediaSipSession";
public static CallbackContext callCallback;
private CallbackContext RTCPCallbackContext;
private Dialog dialog;
And I also add the source-file tag in my plugin.xml ( android-jain-sip-ri-1.2.342.jar have the class which name android.javax.sip)
<source-file src="libs/android-4.1.1.4.jar" target-dir="libs/android-4.1.1.4.jar"></source-file>
<source-file src="libs/android-jain-sip-ri-1.2.342.jar" target-dir="libs/android-jain-sip-ri-1.2.342.jar"></source-file>
so I run ionic Cordova build android, expect Ionic will build an android APK for android platform, but I get the error, it say
error: package android.javax.sip does not exist
import android.javax.sip.Dialog;
symbol: class Dialog
location: class MediaSipSession
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
hope anyone can fix this problem.
I found the way to solve this problem.
If you want to use the library, should use the lib-file tag to define the .jar file, not the source-file tag : )

Module has no exported member AnimationTransitionEvent

ERROR in node_modules/ng2-toastr/src/toast-container.component.d.ts(1,48): error TS2305: Module '"D:/angular basic/my-dream-app/node_modules/#angular/core/core"' has no exported member 'AnimationTransitionEvent'.
using ng2-toastr {ToastsManager} in Angular6
Follow this URL it will get resolved.
It has proper steps as below:
Change ng2-toastr to ngx-toastr and set the version to 8.10.2.
Run npm install to download the package
Assuming you were importing ng2-toastr.min.css somewhere in your app.scss or angular.json, import this instead: #import '~ngx-toastr/toastr.css';
Replace ToastsManager with ToastrService, imported from ngx-toastr:
import { ToastrService } from 'ngx-toastr';
Replace ToastModule with ToastrModule (most likely you are importing this in your app.module.ts file:
import { ToastrModule } from 'ngx-toastr';
If you were calling toastr.setRootViewContainerRef anywhere in your code, that can be deleted since it's no longer needed.
AnimationTransitionEvent has been renamed to AnimationEvent. Please import it from #angular/animations.

How to use HashLocationStrategy for router in angular2-beta.20 in dart?

I tried to use the router in angular2-beta.20 in Dart with the HashLocationStrategy.
But I couldn't find any docs, except for
this link to angular2-beta.15 docs, which are incomplete.
The example shows TypeScript imports instead of Dart ones.
So I tried to import package:angular2/router.dart, but the Dart Analyzer keeps complaining that it can not find LocationStrategy and HashLocationStrategy
Also I don't know, how to write the import exactly, because a top-level provide function, as in the example above, seems non existent.
provide(LocationStrategy, {useClass: HashLocationStrategy})
After some research I found the following:
LocationStrategy and HashLocationStrategy are now part of
package:angular2/platform/common.dart instead of package:angular2/router.dart.
The bootstrap()- method is platform specific, so we need to import package:angular2/platform/browser.dart.
We need to import package:angular2/router.dart to have ROUTER_PROVIDERS available in bootstrap() method.
Here is a working code example for the dart file initializing :
// needed to import "bootstrap" method
import 'package:angular2/platform/browser.dart';
// needed to import LocationStrategy and HashLocationStrategy
import 'package:angular2/platform/common.dart';
// needed for Provider class
import 'package:angular2/angular2.dart';
// needed to import ROUTER_PROVIDERS
import 'package:angular2/router.dart';
// import your app_component as root component for angular2
import 'app_component.dart';
void main() {
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
const Provider(LocationStrategy, useClass: HashLocationStrategy)
]);
}
Hope this helps somebody! :)

AngularDart: 'nGBootstrap is not defined' error

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.

Resources