Build Angular Apps On Mac Rating: 7,9/10 9752 reviews

Angular is a JavaScript framework, created my Misko Hevery and maintained by Google. It’s an MVC (Model View Vontroller). You can visit the official page to learn more about it.

Dec 06, 2017  Angular CLI is a Command Line Interface, that helps you to build Angular apps using nodejs style. Also, it performs all the tedious tasks that you need while creating an Angular app. The people who find difficult to perform or scaffolding their apps, this tools is dedicated to them. The updated Angular project template provides a convenient starting point for ASP.NET Core apps using Angular and the Angular CLI to implement a rich, client-side user interface (UI). The template is equivalent to creating an ASP.NET Core project to act as an API backend and an Angular.

Right now, the latest version of Angular is 5.2.10. There is first generation 1.x and second generation 2.x, and the two generations are totally different in their structures and methods. Don’t worry if you feel confused about the version, because in this article we will be using the second generation 2.x

Table of contents

  • Adding an item (learn how to submit a form in Angular )
  • Removing an item (learn how to add an event in Angular)
  • Angular animation (learn how animate the components )

Those sed commands works on both GNU/BSD/Mac. Links: Angular - Prod Build not generating unique hashes sed in-place flag that works both on Mac (BSD) and Linux RE error: illegal byte sequence on Mac OS X Inline if shell script How to loop over files in directory and change path and add suffix to filename. Learn to build Angular apps like a pro. Angular is one of the most popular frameworks for building client apps with HTML, CSS and TypeScript. Put simply, Angular is a must-have on your resume. Lucky for you, this course is a full-on, deep-dive into Angular that will give you the competitive edge you’re looking for.

Prerequisites:

  • Node.js

Check if node.js is installed in your computer. Learn more about installation.

  • npm

npm (node package manager) is installed with Node.js

Check the node.js version:

npm:

Angular-CLI

You should have the latest version of Angular-CLI. Learn more about Angular CLI here, and find the instructions for installation.

Install Angular-cli:

And finally, you should have:

  • Basic knowledge of JavaScript
  • HTML and CSS fundamentals

You don’t need to have any knowledge of Angular.

Now that we have the environment to run our Angular app, let’s get started!

Creating our first app

We will use angular-cli to create and generate our components. It will generate services, router, components, and directives.

To create a new Angular project with Angular-cli, just run:

The project will be generated automatically. Let’s create our to-do app!

Then, open the files in your text editor. I use Sublime text, but you can choose any editor.

Here’s what the app structure looks like:

Don’t worry if you are confused about the files. All of our work will be in the app folder. It contains five files:

Note: Angular 2 usesTypeScript, in which files end with “.ts”extension.

To make a nice interface for our app, we will use the Bootstrap 4 Framework.

Include bootstrap cdn in index.html:

Run the app in your terminal:

The app will run in http://localhost:4200/

All is well ?!

Now let’s do some HTML structuring. We will use Bootstrap classes to create a simple form.

app.component.html:

In app.component.css:

To capture the input value in Angular 2, we can use the ngModel directive. You can insert a variable as an attribute inside the input element.

To create a variable as an attribute, use # followed by the variable’s name.

Now get the “todo” variable value:

All is well ?!

Now we have to store the value captured from the input. We can create an empty array in app.component.ts inside the AppComponent class:

Then we have to add a click event to our button that pushes the value captured into “todoArray”.

app.component.html:

In app.component.ts:

Use console.log(this.todoArray) to see Array value

Fetch data from “todoArray”

Now we have to fetch data stored in “todosArray.” We will use the *ngFor directive to loop through the array and extract the data.

app.component.html:

After fetching data:

The data will now be fetched automatically when we click the add button.

Styling the app

I like to use Google-fonts and Material-icons, which are free to use.

Include Google fonts inside app.component.css:

And Material-icons inside index.html:

After adding some styling to our app, it will look like this:

To use Material icons:

Add “delete” and “add” icons in app.component.html:

For styles in app.component.css:

Our app is almost done, but we need to add some features. A delete functionality should let users click a delete icon and delete an item. It would also be great to have the option to enter a new item with the return key, instead of clicking the add button.

Deleting items

To add the delete functionality, we will use the “splice” array method and a for loop. We will loop through “todoarray” and extract the item we want to delete.

Add a (click) event to delete icon and give it “todo” as parameter :

In app.component.ts:

When you click delete, this should show up in the console:

Now we have to loop through “todoArray” and splice the item we clicked.

In app.component.ts:

The result:

Awesome ?!!

How To Start Angular App

Entering to add items

We can add a submit event to the form:

We need to add the variable “#todoForm” to the form and give it “ngForm” as a value. In this case, we just have one field so we will just get a single value. If we have multiple fields, the submit event will return the values of all the fields in the form.

app.component.html

in app.component.ts

Check the console. It will return an object of values:

So now we have to push the returned value to “todoArray”:

Here we are ?. The value is inserted without needing to click the add button, just by clicking “enter”:

One more thing. To reset the the form after submitting, add the “resetForm()” build-in method to submit the event.

The form will reset after each submit now:

Adding animations

I like to add a little touch of animations. To add animation, import the animations components in your app.component.ts:

Then add the animations property to “@component” decorator:

Now the items have a nice effect when they’re entered and deleted.

All the code

app.component.ts

app.component.html

app.component.css

We are done ?. You can find the files and code on Github.

See the Demo

Conclusion

Angular is easier than you think. Angular is one of the best JavaScript libraries, and it has great support and a nice community. It also has tools that make working with Angular fast and easy, like Angular-cli.

Subscribe to this mail-list to learn more about Angular.

SaidHayani@ (@hayanisaid1995) Twitter
The latest Tweets from SaidHayani@ (@hayanisaid1995). #Web_Developer /#Frontend / #Back_end(#PHP &…twitter.com

Here are some of the best online courses to learn Angular for free:

Angular 1.x

  • Shaping with Angular

Angular 2.x (recommended)

  • learn Angular2 (coursetro)
-->

The updated Angular project template provides a convenient starting point for ASP.NET Core apps using Angular and the Angular CLI to implement a rich, client-side user interface (UI).

The template is equivalent to creating an ASP.NET Core project to act as an API backend and an Angular CLI project to act as a UI. The template offers the convenience of hosting both project types in a single app project. Consequently, the app project can be built and published as a single unit.

Create a new app

If you have ASP.NET Core 2.1 installed, there's no need to install the Angular project template.

Create a new project from a command prompt using the command dotnet new angular in an empty directory. For example, the following commands create the app in a my-new-app directory and switch to that directory:

Run the app from either Visual Studio or the .NET Core CLI:

Open the generated .csproj file, and run the app as normal from there.

The build process restores npm dependencies on the first run, which can take several minutes. Subsequent builds are much faster.

Ensure you have an environment variable called ASPNETCORE_Environment with a value of Development. On Windows (in non-PowerShell prompts), run SET ASPNETCORE_Environment=Development. On Linux or macOS, run export ASPNETCORE_Environment=Development.

Run dotnet build to verify the app builds correctly. On the first run, the build process restores npm dependencies, which can take several minutes. Subsequent builds are much faster.

Run dotnet run to start the app. A message similar to the following is logged:

Navigate to this URL in a browser.

Warning

The app starts up an instance of the Angular CLI server in the background. A message similar to the following is logged:NG Live Development Server is listening on localhost:<otherport>, open a browser to http://localhost:<otherport>/. Ignore this message—it's not the URL for the combined ASP.NET Core and Angular CLI app.

The project template creates an ASP.NET Core app and an Angular app. The ASP.NET Core app is intended to be used for data access, authorization, and other server-side concerns. The Angular app, residing in the ClientApp subdirectory, is intended to be used for all UI concerns.

Add pages, images, styles, modules, etc.

The ClientApp directory contains a standard Angular CLI app. See the official Angular documentation for more information.

There are slight differences between the Angular app created by this template and the one created by Angular CLI itself (via ng new); however, the app's capabilities are unchanged. The app created by the template contains a Bootstrap-based layout and a basic routing example.

Run ng commands

In a command prompt, switch to the ClientApp subdirectory:

If you have the ng tool installed globally, you can run any of its commands. For example, you can run ng lint, ng test, or any of the other Angular CLI commands. There's no need to run ng serve though, because your ASP.NET Core app deals with serving both server-side and client-side parts of your app. Internally, it uses ng serve in development.

Build Angular App

If you don't have the ng tool installed, run npm run ng instead. For example, you can run npm run ng lint or npm run ng test.

Install npm packages

To install third-party npm packages, use a command prompt in the ClientApp subdirectory. For example:

Create New Angular App

Publish and deploy

Build Angular Apps On Mac Computer

In development, the app runs in a mode optimized for developer convenience. For example, JavaScript bundles include source maps (so that when debugging, you can see your original TypeScript code). The app watches for TypeScript, HTML, and CSS file changes on disk and automatically recompiles and reloads when it sees those files change.

Download Global Nav Open Menu Global Nav Close Menu; Apple; Shopping Bag +. Search Support. Appked is the Apple macOS and Mac OS X Apps & Games download site. MacApps Download Cracked Mac Apps and Games for Free, Updated Daily with all the Best Most Popular Mac Apps in the Mac App Store.

In production, serve a version of your app that's optimized for performance. This is configured to happen automatically. When you publish, the build configuration emits a minified, ahead-of-time (AoT) compiled build of your client-side code. Mac os x 10.6.8 software update. Unlike the development build, the production build doesn't require Node.js to be installed on the server (unless you have enabled server-side rendering (SSR)).

You can use standard ASP.NET Core hosting and deployment methods.

Run 'ng serve' independently

The project is configured to start its own instance of the Angular CLI server in the background when the ASP.NET Core app starts in development mode. This is convenient because you don't have to run a separate server manually.

There's a drawback to this default setup. Each time you modify your C# code and your ASP.NET Core app needs to restart, the Angular CLI server restarts. Around 10 seconds is required to start back up. If you're making frequent C# code edits and don't want to wait for Angular CLI to restart, run the Angular CLI server externally, independently of the ASP.NET Core process. To do so:

  1. In a command prompt, switch to the ClientApp subdirectory, and launch the Angular CLI development server:

    Important

    Use npm start to launch the Angular CLI development server, not ng serve, so that the configuration in package.json is respected. To pass additional parameters to the Angular CLI server, add them to the relevant scripts line in your package.json file.

  2. Modify your ASP.NET Core app to use the external Angular CLI instance instead of launching one of its own. In your Startup class, replace the spa.UseAngularCliServer invocation with the following:

Build Angular Apps On Mac

When you start your ASP.NET Core app, it won't launch an Angular CLI server. The instance you started manually is used instead. This enables it to start and restart faster. It's no longer waiting for Angular CLI to rebuild your client app each time.

Pass data from .NET code into TypeScript code

During SSR, you might want to pass per-request data from your ASP.NET Core app into your Angular app. For example, you could pass cookie information or something read from a database. To do this, edit your Startup class. In the callback for UseSpaPrerendering, set a value for options.SupplyData such as the following:

The SupplyData callback lets you pass arbitrary, per-request, JSON-serializable data (for example, strings, booleans, or numbers). Your main.server.ts code receives this as params.data. For example, the preceding code sample passes a boolean value as params.data.isHttpsRequest into the createServerRenderer callback. You can pass this to other parts of your app in any way supported by Angular. For example, see how main.server.ts passes the BASE_URL value to any component whose constructor is declared to receive it.

Drawbacks of SSR

Not all apps benefit from SSR. The primary benefit is perceived performance. Visitors reaching your app over a slow network connection or on slow mobile devices see the initial UI quickly, even if it takes a while to fetch or parse the JavaScript bundles. However, many SPAs are mainly used over fast, internal company networks on fast computers where the app appears almost instantly.

At the same time, there are significant drawbacks to enabling SSR. It adds complexity to your development process. Your code must run in two different environments: client-side and server-side (in a Node.js environment invoked from ASP.NET Core). Here are some things to bear in mind:

  • SSR requires a Node.js installation on your production servers. This is automatically the case for some deployment scenarios, such as Azure App Services, but not for others, such as Azure Service Fabric.

  • Enabling the BuildServerSideRenderer build flag causes your node_modules directory to publish. This folder contains 20,000+ files, which increases deployment time.

  • To run your code in a Node.js environment, it can't rely on the existence of browser-specific JavaScript APIs such as window or localStorage. If your code (or some third-party library you reference) tries to use these APIs, you'll get an error during SSR. For example, don't use jQuery because it references browser-specific APIs in many places. To prevent errors, you must either avoid SSR or avoid browser-specific APIs or libraries. You can wrap any calls to such APIs in checks to ensure they aren't invoked during SSR. For example, use a check such as the following in JavaScript or TypeScript code:

Additional resources