Example: AngularJS module _ AngularJS

Source: Internet
Author: User
This article mainly introduces the modules in AngularJS. This article describes examples of its application modules and controller modules. For more information, see how AngularJS supports modularity. The module is used to logically represent services, controllers, applications, and so on, and keep the code clean and tidy. We define a module in a separate js file and name it in the form of a module. js file. In this example, we will create two modules.

  1. Application Module-used to initialize the controller Application
  2. Controller Module-used to define the Controller

Application Module

mainApp.jsvar mainApp = angular.module("mainApp", []);

Here, we have declared the application mainApp module using the angular. module function. We have passed an empty array to it. This array usually contains subordinate modules.
Controller Module

StudentController. js

mainApp.controller("studentController", function($scope) {  $scope.student = {   firstName: "Mahesh",   lastName: "Parashar",   fees:500,   subjects:[     {name:'Physics',marks:70},     {name:'Chemistry',marks:80},     {name:'Math',marks:65},     {name:'English',marks:75},     {name:'Hindi',marks:67}   ],   fullName: function() {     var studentObject;     studentObject = $scope.student;     return studentObject.firstName + " " + studentObject.lastName;   }  };});

Here, we have declared that the controller uses the mainApp. controller function of the studentController module.
Modules

..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.