Quickstarters
CRUD Samples
How to Build a Basic CRUD App with Angular?
41 min
introduction in this guide, we will walk you through the process of constructing a basic crud (create, read, update, delete) application using angular you’ll learn how to develop an application that efficiently manages data operations by leveraging angular’s robust framework to start, you'll create and configure a new back4app project titled basic crud app angular , which will serve as the backbone of your backend data management next, you'll design a scalable database model by outlining detailed collections and fields—either manually or with the assistance of the back4app ai agent this step guarantees that your system is well prepared to handle all crud functionalities after setting up your schema, you will explore the back4app admin app, an intuitive drag and drop interface, to easily manage your collections and records finally, you will integrate your angular frontend with back4app using rest/graphql (or the parse sdk, if preferred), while also implementing advanced security measures to safeguard your backend by the end of this tutorial, you will have built a production ready angular application featuring user authentication and comprehensive crud capabilities key takeaways master how to construct crud applications that handle data efficiently with a reliable backend gain practical insights into creating a scalable data model and linking it to an angular frontend learn how to utilize the back4app admin app’s user friendly interface for effortless data management understand deployment strategies, including docker containerization, to rapidly launch your angular app prerequisites before you begin, please ensure you have the following a back4app account with a new project setup need help? check out getting started with back4app https //www back4app com/docs/get started/new parse app an angular development environment install angular cli by running npm install g @angular/cli and create a new project using ng new make sure node js (version 14 or above) is installed a basic understanding of typescript, angular, and rest apis for a refresher, visit the angular documentation https //angular io/docs step 1 – setting up your project launching a new back4app project sign in to your back4app account click the “new app” button from your dashboard enter the project name basic crud app angular and follow the setup prompts create new project once the project is created, it will appear on your back4app dashboard, providing a strong foundation for your backend configuration step 2 – crafting your database schema constructing your data model for this crud application, you will define several collections below are examples of the collections and their fields that will form the basis of your database schema these collections empower the application to perform essential crud operations 1\ items collection this collection stores information for each item field data type details id objectid auto generated unique identifier title string the title of the item description string a brief summary of the item created at date timestamp for when the item was added updated at date timestamp for the latest update 2\ users collection this collection maintains user credentials and authentication data field data type description id objectid auto generated unique identifier username string a unique identifier for the user email string a distinct email address password hash string securely hashed password for authentication created at date timestamp indicating when the account was created updated at date timestamp of the most recent update you can set up these collections manually in the back4app dashboard by creating a new class for each and adding columns to define the fields create new class add columns by choosing a data type, naming the field, setting a default value, and marking whether it is required create column leveraging the back4app ai agent for schema setup the back4app ai agent is a versatile tool available in your dashboard that allows you to automatically generate your database schema based on a descriptive prompt this feature saves time and ensures that your backend is perfectly tailored for crud operations steps to use the ai agent open the ai agent log in to your back4app dashboard and find the ai agent option describe your schema input a detailed prompt outlining the collections and fields you need review and confirm after submission, review the generated schema and apply it to your project sample prompt create the following collections in my back4app project 1\) collection items \ fields \ id objectid (auto generated primary key) \ title string \ description string \ created at date (auto generated) \ updated at date (auto updated) 2\) collection users \ fields \ id objectid (auto generated primary key) \ username string (unique) \ email string (unique) \ password hash string \ created at date (auto generated) \ updated at date (auto updated) this ai powered approach streamlines the process and ensures a consistent, optimized schema step 3 – activating the admin app & managing crud operations a glimpse at the admin app the back4app admin app provides a no code, drag and drop interface that allows you to manage your backend data effortlessly with it, you can easily perform crud operations such as adding, viewing, modifying, and deleting records activating the admin app navigate to the “more” menu in your back4app dashboard select “admin app” and click “enable admin app ” set up your admin credentials create your initial admin user, which will also configure roles (e g , b4aadminuser ) and system collections enable admin app after activation, log into the admin app to manage your collections and records admin app dashboard utilizing the admin app for crud tasks within the admin app, you can add new records click “add record” in any collection (e g , items) to create new entries view & edit records select a record to see its details or update its fields remove records use the delete option to remove outdated records this intuitive interface greatly simplifies the management of your backend data step 4 – connecting your angular frontend to back4app now that your backend is fully set up and managed through the admin app, it’s time to link your angular frontend to back4app option a integrating the parse sdk with angular install the parse sdk npm install parse set up parse in your angular project create a configuration file (e g , src/app/parse config ts ) // src/app/parse config ts import parse from 'parse'; // replace with your actual back4app credentials parse initialize('your application id', 'your javascript key'); parse serverurl = 'https //parseapi back4app com'; export default parse; 3\ implement parse in an angular component for example, create a component to fetch and display items ```typescript // src/app/components/items list/items list component ts import { component, oninit } from '@angular/core'; import parse from ' / /parse config'; @component({ selector 'app items list', templateurl ' /items list component html', styleurls \[' /items list component css'] }) export class itemslistcomponent implements oninit { items any\[] = \[]; async ngoninit() { const items = parse object extend('items'); const query = new parse query(items); try { const results = await query find(); this items = results; } catch (error) { console error('error retrieving items ', error); } } } and in the html template ( items list component html ) items {{ item get('title') }} – {{ item get('description') }} option b utilizing rest or graphql if you prefer not to use the parse sdk, you can execute crud operations via rest or graphql for example, to fetch items using rest in angular, create a service method like this // src/app/services/items service ts import { injectable } from '@angular/core'; import { httpclient, httpheaders } from '@angular/common/http'; import { observable } from 'rxjs'; @injectable({ providedin 'root' }) export class itemsservice { private apiurl = 'https //parseapi back4app com/classes/items'; constructor(private http httpclient) { } getitems() observable\<any> { const headers = new httpheaders({ 'x parse application id' 'your application id', 'x parse rest api key' 'your rest api key' }); return this http get(this apiurl, { headers }); } } you can integrate these api calls within your angular components as needed step 5 – protecting your backend implementing access control lists (acls) enhance your data security by assigning acls to your objects for example, to create an item accessible only by its owner async function createsecureitem(itemdata any, owneruser any) { const items = parse object extend('items'); const item = new items(); item set('title', itemdata title); item set('description', itemdata description); // assign acl only the owner has read/write access const acl = new parse acl(owneruser); acl setpublicreadaccess(false); acl setpublicwriteaccess(false); item setacl(acl); try { const saveditem = await item save(); console log('secure item created ', saveditem); } catch (error) { console error('error creating item ', error); } } configuring class level permissions (clps) within the back4app dashboard, adjust the clps for each collection to set default access rules, ensuring that only authenticated or authorized users can access sensitive data step 6 – managing user authentication creating and handling user accounts back4app utilizes parse’s user class to manage authentication in your angular project, you can handle user registration and login as follows // src/app/components/auth/auth component ts import { component } from '@angular/core'; import parse from ' / /parse config'; @component({ selector 'app auth', templateurl ' /auth component html', styleurls \[' /auth component css'] }) export class authcomponent { username string = ''; password string = ''; email string = ''; async signup(event event) { event preventdefault(); const user = new parse user(); user set('username', this username); user set('password', this password); user set('email', this email); try { await user signup(); alert('user registration successful!'); } catch (error any) { alert('registration error ' + error message); } } } and the corresponding html template ( auth component html ) register a similar approach can be applied for user login and session management for features such as social logins or password resets, adjust your settings in the back4app dashboard step 7 – deploying your angular frontend back4app’s web deployment feature enables you to host your angular application by deploying code directly from a github repository in this section, you'll prepare your production build, commit your source code, and integrate your repository for deployment 7 1 building your production version open your project directory in a terminal run the production build command ng build prod this command compiles your angular application into an optimized dist/ folder verify the build ensure that the dist/ directory contains the index html and all necessary assets 7 2 structuring and uploading your source code your repository should contain your entire angular project a typical file structure might look like basic crud app angular/ ├── node modules/ ├── src/ │ ├── app/ │ │ ├── app component ts │ │ ├── app module ts │ │ └── components/ │ │ ├── auth/ │ │ │ ├── auth component ts │ │ │ └── auth component html │ │ └── items list/ │ │ ├── items list component ts │ │ └── items list component html ├── angular json ├── package json └── readme md example src/app/parse config ts // src/app/parse config ts import parse from 'parse'; // replace with your actual back4app credentials parse initialize('your application id', 'your javascript key'); parse serverurl = 'https //parseapi back4app com'; export default parse; example src/app/app component ts import { component } from '@angular/core'; import parse from ' /parse config'; @component({ selector 'app root', template ` \<div style="padding 2rem;"> \<h1>items\</h1> \<app items list>\</app items list> \</div> `, styles \[] }) export class appcomponent { } committing your code to github initialize a git repository in your project folder if you haven’t already git init add your project files git add commit your changes git commit m "initial commit for angular frontend" create a github repository for instance, name it basic crud app angular push your code to github git remote add origin https //github com/your username/basic crud app angular git git push u origin main 7 3 linking your github repository with web deployment access the web deployment feature log in to your back4app dashboard, select your project ( basic crud app angular ), and choose web deployment connect your github account follow the prompts to integrate your github account, allowing back4app to access your repository select your repository and branch choose your repository (e g , basic crud app angular ) and the branch (e g , main ) that contains your code 7 4 configuring your deployment settings provide the necessary configuration details build command if your repository lacks a pre built dist/ folder, specify the build command (e g , ng build prod ) output directory set the output directory to dist/your project name so back4app knows where your static files are located environment variables add any required environment variables (such as api keys) in the deployment configuration 7 5 containerizing your angular application with docker if you prefer a docker based deployment, include a dockerfile in your repository for example \# use an official node image to build the angular app from node 16 alpine as build \# set the working directory workdir /app \# copy package files and install dependencies copy package json / run npm install \# copy the rest of the application and build it copy run npm run build prod \# use nginx to serve the built app from nginx\ stable alpine copy from=build /app/dist/your project name /usr/share/nginx/html expose 80 cmd \["nginx", " g", "daemon off;"] include this dockerfile in your repository, then select the docker deployment option in back4app’s web deployment settings 7 6 launching your application click the deploy button once your deployment settings are configured, click deploy monitor the deployment process back4app will pull your code, execute the build command if needed, and deploy your angular app retrieve your url after a successful deployment, back4app will provide a url where your application is live 7 7 testing your deployed application visit the provided url open the url in your browser verify functionality ensure that your angular app loads properly, all routes function as expected, and assets are served correctly troubleshoot if necessary use browser developer tools to identify and resolve any issues check back4app’s deployment logs and your configuration if problems arise step 8 – wrapping up and future directions congratulations! you have successfully built a basic crud application using angular and back4app you set up a project named basic crud app angular , designed comprehensive database collections for items and users, and managed your data using the intuitive admin app additionally, you connected your angular frontend to your backend and implemented robust security measures next steps enhance your frontend extend your angular application with advanced features such as detailed item views, search functionality, and real time updates expand functionality consider integrating additional backend logic (like cloud functions) or implementing role based access control explore further resources check out the back4app documentation https //www back4app com/docs and other angular resources to deepen your understanding with this guide, you are now equipped to build robust, scalable crud backends for your angular applications using back4app happy coding!