小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

AngularJS 模塊

 碼農(nóng)9527 2021-11-12

  AngularJS支持模塊化方法。模塊用于單獨的邏輯表示服務(wù),控制器,應(yīng)用程序等。為保持代碼簡潔,我們在單獨的 js 文件中定義模塊,并將其命名為 module.js文件。 在這個例子中,我們要創(chuàng)建兩個模塊。

AngularJS 模塊

  應(yīng)用模塊 - 控制器用于初始化應(yīng)用程序。

  控制器模塊 - 用于定義控制器。

  應(yīng)用模塊

  mainApp.js

var mainApp = angular.module("mainApp", []);12復制代碼類型:[html]

  在這里,我們聲明了使用 angular.module 函數(shù)的應(yīng)用程序mainApp模塊。我們已經(jīng)傳遞一個空數(shù)組給它。這個數(shù)組通常包含依賴模塊。

  控制器模塊

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;
   }
   };
});1234567891011121314151617181920復制代碼類型:[html]

  在這里,我們聲明了使用 mainApp.controller 函數(shù)的一個控制器 studentController 模塊。

  使用模塊

<div ng-app="mainApp" ng-controller="studentController">..<script src="mainApp.js"></script><script src="studentController.js"></script>123456復制代碼類型:[html]

  這里我們使用 ng-app 指令和控制器使用 ng-controller 指令的應(yīng)用模塊。我們已經(jīng)在主HTML頁面導入 mainApp.js 和 studentController.js。

    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多