Getting started with Portal in Angular
We've made it simple to get started with Portal with our new Portal Angular Component. Here's what you'll need to know to begin.
You'll need a license key to continue. Log in to your account to access the Flatfile dashboard. Head to the Flows section in the left-hand navigation pane and find your license key under the Portal tab.
Install and import
npm install @flatfile/angular@^1 --save
In the Module
In your Angular Module, you'll need to import the FlatfileAdapterModule
from the @flatfile/angular
package.
import { FlatfileAdapterModule } from "@flatfile/angular";
Then you will need to use it in the imports section of the module, and then you'll be ready to use it within your application.
@NgModule({
declarations: [],
imports: [FlatfileAdapterModule],
providers: [],
bootstrap: []
})
Once you have this setup, in your app component file, you will be able to import and access the FlatfileMethods
module for use.
This brings the FlatfileButton
component into your project.
Configure your settings and usage
To launch, the flatfile-button
component, you must have a minimum of settings
, customer
and licenseKey
as properties in your AppComponent.
export class AppComponent implements FlatfileMethods {
title = "Flatfile Angular Setup";
customer = { userId: "12345" };
licenseKey = "License Key Here";
settings = {
type: "test import",
fields: [
{ label: "Name", key: "name" },
{ label: "Email", key: "email" },
],
managed: true,
};
}
Basic Usage
In your component html code, you will then be able to call the flatfile-button
component like below.
<flatfile-button
[settings]="settings"
[customer]="customer"
[licenseKey]="licenseKey"
>
Upload with Flatfile
</flatfile-button>
Styling the Flatfile Button
In order to style the <flatfile-button>
from within your parent component, ensure that your parent component has ViewEncapsulation.None
, pass down a class to <flatfile-button>
, and now you will be able to style the button
one-level down.
template: `
<flatfile-button
[settings]=“settings”
[customer]=“customer”
[licenseKey]=“licenseKey”
class=“flatfile-button”
>
Upload with Flatfile
</flatfile-button>
`,
encapsulation: ViewEncapsulation.None,
styles: [`
.flatfile-button button {
border: 0;
border-radius: 3px;
padding: 1rem;
background: #3B2FC9;
color: #fff;
}
`],
}) export class MyDemoComponent implements FlatfileMethods {
// ...
}
Here is a list of all the properties that are configurable with the <flatfile-button>
component. Visit out settings guide to learn about each in greater depth.
settings
- Required - Pass in an object containing the importtype
and yourfields
. For a list of the other optional settings, check out our options documentation here.customer
- Required - Pass in an object that identifies the customer uploading the file. This refers the thesetCustomer()
function on our SDK, and the same object should be passed in here.licenseKey
- Required - In order to access our product, a license key is required. The license key can be found in your dashboard by logging in here.onCancel
- This allows you to pass in a callback function that will run if the user cancels out of the import.onData
- This allows you to return a new Promise to handle the Flatfile results when returned.onRecordChange
- This provides access to Flatfile's record hooks when a record changes.onRecordInit
- This provides access to Flatfile's record hooks when a record initializes.fieldHooks
- This allows you to pass in one or more field hooks as separate callback functions.
Try our example in CodeSandbox.