dnn-sxc-angular
Connector for angular 4.3+ (git | web) if you're using
- the open source platform DNN 7+ (git | web)
- and/or the open source CMS 2sxc 7+ (git | web)
This is a helper system which
- automatically provides all important dnn-parameters (module ID, security token, etc.) to angular
- adds an Http Interceptor for the HttpClient which automatically applies these parameters to all requests
- prevents the enter-key from causing DNN form submits (you can override this)
It uses observables to make it happen, thereby avoiding timing / async problems common in this scenario.
How to get this package
It's published on npm, so the most common way is to get it using npm install:
npm install -d @2sic.com/dnn-sxc-angular
How To Use
Setup
The following instructions help you get started, but it's best to also look at a real app using this - like the Angular Directory App.
Make sure your application uses the Http Interceptor by adding the important providers to app.module.ts, so you'll need to add:
import { DnnSxcModule } from '@2sic.com/dnn-sxc-angular'
and this module to the @NgModule - here's an example from the Angular Directory App, yours will look a bit different.
@NgModule({
declarations: [
AppComponent
],
imports: [
DnnSxcModule,
HttpClientModule,
BrowserModule,
FormsModule,
DirectoryModule,
RouterModule.forRoot(appRoutes)
],
bootstrap: [AppComponent]
})
export class AppModule { }
Now, make sure initializations happen, by changing your app.component.ts from
export class AppComponent {...}
to
export class AppComponent extends DnnAppComponent {
constructor(
element: ElementRef,
context: Context,
) {
super(element, context);
}
}
You can compare it with the example from the Angular Directory App. That's it!
Using WebAPIs inside DNN
This will now work automatically, because all headers etc. are now automatically added by the system.
Getting ModuleId, TabId, etc.
There is a Context
object which provides these properties as observables. Just inject Context
in your controller, service or whatever and access it from there.
Using 2sxc Content-Items, Queries and APIs
This package contains a Data
object, which provides 3 observable streams
To use them, best check out the demo app or simply work through TypeScript intelisense - we documented all the commands.
Getting the sxc
Instance Object
If you need this, you can always get it as an observable from the Context
object.
Internal Notes
Todo
- create & test simple app-api access
- enhance the content-manager to provide write commands (ATM read-only)