9951 explained code solutions for 126 technologies


angularjsHow do I get started with AngularJS?


Getting started with AngularJS is easy. Here are the steps to get started:

  1. Include the AngularJS library in your HTML page.
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
  1. Add the ng-app directive to the root HTML element of your application. This will tell AngularJS that the HTML element and its children constitute an AngularJS application.
<html ng-app>
  1. Add the ng-model directive to the HTML elements you want to bind to a property on the $scope object.
<input type="text" ng-model="name">
  1. Add the ng-controller directive to the HTML element which will be the parent of the HTML elements you want to bind to a property on the $scope object.
<div ng-controller="MyController">
  1. Create a controller in your JavaScript code that will be responsible for initializing the $scope object.
function MyController($scope) {
    $scope.name = '';
}
  1. Add the controller to the ng-app module.
var app = angular.module('myApp', []);
app.controller('MyController', MyController);
  1. Initialize the AngularJS application using the ng-app directive.
<html ng-app="myApp">

For more information, please refer to the AngularJS Documentation.

Edit this code on GitHub