Kylo UI - Create new typescript module - angularjs

I have a doubt about the way to work with Kylo and UI structure.
According to the site http://kylo.readthedocs.io/en/v0.8.3/developer-guides/KyloDeveloperGuide.html?highlight=angular2 it says:
Most of the Kylo UI depends on AngularJS and AngularJS Material but a few parts have been upgraded to Angular 2 and Covalent. New plugins should be written in Typescript and use Angular 2 for future compatibility.
It says that new plugins should be written in angular2 and typescript, but all the examples and the core components are written in AngularJS.
One example is this one: https://github.com/Teradata/kylo/tree/master/samples/plugins/example-module/example-module-ui
I would like to know the Typescript and Angular2 alternative for that module, including routing, is there any live example ?

I've tested that Angular 2 does work if the code is added directly to the kylo-ui-app project but I don't think Kylo's plugin system supports Angular 2 right now.
The only difference from standard Angular 2 is that Kylo uses UI-Router instead of the Angular Router, but the syntax is very similar. From memory I think these are the steps I used:
1) Add a new route to routes.js:
{
name: 'contacts.**',
url: '/contacts',
loadChildren: './contacts/contacts.module#ContactsModule'
}
2) Add the child states to your module:
#NgModule({
imports: [ UIRouterModule.forChild({ states: CONTACTS_STATES }), /* ... and any other modules */ ],
declarations: [ ContactComponent, /* ... and any other components */ ],
providers: [ ContactsDataService ],
})
export class ContactsModule { }
3) The component for each state should be specified under views.content:
{
name: 'contacts',
url: '/contacts',
views: {
"content": {
component: ContactsComponent,
}
}
}

Related

Is there a way to run a React app inside an Angular site without the routes conflicting?

I have an Angular 14 application that has the build files for a React application being served in a folder alongside it, as such.
dist
|_apps
|_react-app-build
|
|
|_main.js, runtime.js, etc
my routing-module is as follows
{path: '', component: HomepageComponent},
{path: 'projects', component: ProjectsPageComponent},
{path: 'contact', component: ContactPageComponent},
{path: '**', redirectTo: "/"},
I need to be able to access the react app, but its routes keep being picked up by the Angular router and redirected to the root. Is there any way to force the Angular router to completely ignore the routes for the React application (/apps/react-app-build/*)?
So far I have tried setting the base href to something other than the root <base href="/site">
as well as adding
#NgModule({
imports: [RouterModule.forRoot(routes,
{
---
useHash: true
---
})],
exports: [RouterModule]
})
to the routing module, all to no avail.
Read more on Webpack Module Federation. It allows you to share separate JavaScript applications using lazy loaded routes. Does not matter whether the application is react or angular

Using Ui-Router and adhering to good design patterns

Learning Angular. Working with 1.6.6.
Trying to use ui.router, running into an issue with injecting components.
I've been using the following as resources to structure my project:
AngularJS: Understanding design pattern
https://github.com/angular-app/angular-app
Both these resources suggest using module as a container for the code underneath them. For example from my own project:
angular.
module('randomTownGenerator.module', [
'randomTown.service',
'randomTown.controller'
]);
Each of those dependancies is defined in its own file. When I specify the above module as the component for the the route:
var randomTownGenerator = {
name: 'randomTownGenerator',
url: '/random-town',
component: 'randomTownGenerator.module'
}
I get:
Error: [$injector:unpr] Unknown provider: randomTownGenerator.moduleDirectiveProvider <- randomTownGenerator.moduleDirective
How can I pass the randomTownGenerator.module, which is just a wrapper around the service, template, and controller, to ui.router?
You have provided a module where it is expecting an angular component.
component: 'randomTownGenerator.module'
Here angular-ui-router is expecting a angular component to generate as the view for the state 'randomTownGenerator'. Please refer the angularjs documentation on how to create a component.
https://code.angularjs.org/1.6.6/docs/guide/component
You are trying to mixup the angularjs earlier version of injecting a module and new way of injecting module.
You should provide a component as a view with the later version so that will be loaded when it is required.
var States = {
"app": {
path: "",
routing: null,
definition: {
name: "app",
url: "",
onEnter: function () {
console.info("App state entered.");
},
params: {
//
},
resolve: {
//
},
views: {
"app#": {
component: "appComponent"
}
},
abstract: true
}
}
};
where component should be a component not a module. Here is a complete example of how to create states with ui-router and angularjs 1.6 version

Angular 2 cannot include Material lib

I am using the Microsoft.AspNetCore.SpaTemplates example of angular 2, I installed the angular/materiel npm module and tried to include that for use of the input material.
EDIT -- New question posted regarding removing the server-side rendering.
Link -- Click Here
I tried to import it in app.module.ts and after doing so cannot seem to get my application to load anymore.
#NgModule({
bootstrap: [ AppComponent ],
declarations: [
AppComponent,
HeaderComponent,
LoginComponent
],
imports: [
UniversalModule, // Must be first import. This automatically imports BrowserModule, HttpModule, and JsonpModule too.
RouterModule.forRoot([
{ path: '', redirectTo: 'account', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{ path: '**', redirectTo: 'account' }
]), MaterialModule
]
})
Now I am trying to create a simple login view with an email and password input box. I wanted to use angular material to make it look better.
Here is my exception on page load.
An unhandled exception occurred while processing the request.
Exception: Call to Node module failed with error: Error: This method is not implemented in Parse5DomAdapter: getCookie
at _notImplemented (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:91062:12) [angular]
at Parse5DomAdapter.module.exports.Parse5DomAdapter.getCookie (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:91657:69) [angular]
at CookieXSRFStrategy.configureRequest (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:63677:109) [angular]
at XHRBackend.createConnection (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:63726:32) [angular]
at httpRequest (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:64076:24) [angular]
at Http.request (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:64185:38) [angular]
at Http.get (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:64199:25) [angular]
at AccountService.ping (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\main-server.js:22373:30) [angular]
at new AccountService (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\main-server.js:22370:14) [angular]
at CompiledTemplate.proxyViewClass.View_AppComponent0.createInternal (/AppModule/AppComponent/component.ngfactory.js:15:30) [angular]
at CompiledTemplate.proxyViewClass.AppView.create (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:11951:25) [angular]
at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.createInternal (/AppModule/AppComponent/host.ngfactory.js:15:19) [angular]
at CompiledTemplate.proxyViewClass.AppView.createHostView (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:11964:25) [angular]
at ComponentFactory.create (C:\Users\baile\Source\Repos\Programming2017\BankSoftware\ClientApp\dist\vendor.js:7361:29) [angular]
I now understand that the Universal Module is what is creating pre-rendering. This is really great and all except to be completely honest I don't need it.
To revise my question now. How can someone take the Microsoft.AspNetCore.SpaTemplate for angular 2 and remove the Universal Module and still have a working angular website. Simply removing the Universal Module from the imports causing other errors to start showing up. What changes need to be made throughout other sections of the template, and am I losing anything aside from server-side pre-rendering?
I had the same issue and fixed it by putting the MaterialModule before the UniversalModule. I know the SPA template says it should go first, but that order seemed to break it.
imports: [
MaterialModule.forRoot(),
UniversalModule, // Must be first import. This automatically imports BrowserModule, HttpModule, and JsonpModule too.
RouterModule.forRoot([
{ path: '', redirectTo: 'account', pathMatch: 'full' },
{ path: 'account', component: AccountListComponent },
{ path: 'detail/:id', component: AccountDetailComponent },
{ path: '**', redirectTo: 'account' }
])
],
Edit - Actually, it looks to be more complicated than this. Here is a GitHub issue on it:
https://github.com/angular/material2/issues/308
I ended up pulling out the UniversalModule because Angular Material was more important to me than server side rendering at this point. There are a few changes you would need to make to get the SPA template to work with Angular Material. Let me know if you would like more help.
Edit
I have down voted this question since the OP marked my answer, then un-marked despite considerable effort to assist. The answer I provided is the correct answer.

No provider for $scope! error when using a angular 1 directive in an angular 2 app

I have an angular 2 App built with angular-cli and I need to use an angular 1 directive in one of my components (to re-use it from a different application). I followed the steps from:
https://angular.io/docs/ts/latest/guide/upgrade.html#!#using-angular-1-component-directives-from-angular-2-code
But now I got to this error and cannot get past it. I am using angular2.0.2 (I managed to build a hybrid app in the past with the beta version but it was an angular1 app and I used angular 2 components with downgrade function of the adapter).
In my app.module.ts I have:
import { UpgradeAdapter } from '#angular/upgrade';
const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule));
const HeroDetail = upgradeAdapter.upgradeNg1Component('heroDetail');
#NgModule({
imports: [
BrowserModule,
...
],
declarations: [
...
HeroDetail
]
})
export class AppModule { }
and my hero-detail.component.ts looks like this:
export const heroDetail = {
templateUrl: 'hero-detail.html',
controller: function() {
}
};
and my hero-detail.html looks like this:
<h2>Windstorm details!</h2>
I try to use the directive in another angular 2 component simply by adding in the template:
When I run ng serve, the application compiles fine but when I try to load the page I get the mentioned error.
Any suggestions on how I can move forward with this?
It seems you have incorrect bootstrap logic.
It's actually not quite obvious, make sure that:
you don't bootstrap any ng2 component with #NgModule({bootstrap:[ ... ]}). Instead, you should have empty ngDoBootstrap() { } method in your main module.
root template is ng1 template. I.e. in your index.html you should have only ng1 components or downgraded ng2 components. You can have ng2 component as a root, but you need to downgrade it first.
Official upgrade guide contains an example of DOM structure:
... which ensures that ng2 injectors have all required providers from ng1.

Angular 1.5 and new Component Router

I'm using angular 1.5 beta 2 and the new router from Angular 2 alpha 45.
I couldn't find examples of usage for the latest router with Angular 1.
I can find examples of the usage of the router for Angular 2, using #RouteConfig.
Can someone explain how I would configure an angular 1 controller? And, if possible, a full working example?
Update They have stopped working on this version of the Router and started a version 3 with different APIs. As of June 20, 2016 there was no recommended way for using the router v3 with Angular 1. I'm not sure if this has changed since. This question and answer below relates to Router v2 (aka ComponentRouter).
Obsolete API
A few sites indicate that a component in Angular 1 (for the purpose of the new router) is a controller registered as [name]Controller and a template picked up from component/[name]/[name].html. This is now obsolete.
New API
This discussion contains recent information, explaining how to get the latest Angular 1 new router version.
The component used in the configuration is mapped to a directive registered with the component name. See this sample.
angular.module('app.home', [])
.directive('home', function() {
return {
template: 'Hello {{ home.text }}',
controller: function HomeController() {
this.text = 'World';
},
controllerAs: 'home'
}
});
With Angular 1.5 there is a new syntax for registering components, see here. I've used it with this syntax:
angular.module('app.home', [])
.component('home', {
restrict: "EA",
template: 'Hello {{ home.text }}',
controller: function HomeController() {
this.text = 'World';
}
// to configure a child route
//,$routeConfig: [
// { aux: "/son", component: "son", as: "Left" },
// { aux: "/daughter", component: "daughter", as: "Left" }]
});
Although it is pretty new at this point you can also use a root component with the new angular router. This component could take additional components as children.
I followed Pete Bacon Darwin's example to get a version going.
https://github.com/petebacondarwin/ng1-component-router-demo
Notice in his version The main component has $router.config passed in the run block and identifies children with 3 dots.
.run(function($router) {
$router.config([
{ path: '/...', name: 'App', component: 'app', useAsDefault: true }
]);
I am using angular 1.5.0 to follow his github. I ran into issues playing with release some of the release candidates.

Resources