Monday, March 20, 2017

Implement Angular JS "Hello World"

Step-1:


  • Create the MVC solution, Right click on the solution name in "Solution Explorer" and select "Manage NuGet Package" and download angluar files.
  • Add the Angular JS referance in bundle.js or _Layout.cshtml:
    • BundleConfig.cs:
      • bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(                      "~/Scripts/bootstrap.js","~/Scripts/angular.min.js","~/Scripts/ng-grid.js","~/Scripts/Myangualr.js","~/Scripts/respond.js"));
Step-2:

  • Create new JavaScript file called "Myangualr.js". Add below code
    • Create angular Module:
      • angular.module("myAppModule", ['ngGrid',])
    • Create angular Controller for the above module:
      • var myAngualrApp = angular.module("myAppModule", ['ngGrid', ])
      • myAngualrApp.controller("myController", function ($scope) {   $scope.DispalyText="Hello World !!!" // Your Code is here }})
Step-3:

  • Create html file and add the below code:
    • <div ng-app="myAppModule">
    •             <div ng-controller="myController">                
    •                 {{DispalyText}}
    •             </div>
    •         </div>
  • Run the soultion and out put will display in the browser...



No comments:

Post a Comment