当前位置:首页>开发>正文

面试会问angularjs什么问题 angular.module什么意思

2023-05-27 10:49:16 互联网 未知 开发

 面试会问angularjs什么问题 angular.module什么意思

面试会问angularjs什么问题

对于angularjs中必须要问的就是指令,其实还有angular的配置文件,angularjs的provider,constant,factory,service区别什么的。指令很重要,面试过程中一般都会问

angular.module什么意思

模块可以说是AngularJS 的根本。它包含配置、控制、过滤、工厂模式、指令及其它模块。
  如果你熟悉.NET平台,但初步学习Angular。下面的表格是一个简要的对比,帮助你理解Angular中的角色扮演情况:

  例如,下面的代码使用控制器、过滤器和指令创建了一个模块:
  // the main (app) module
  var myApp = angular.module("myApp", [])
  // add a controller
  myApp.controller("myCtrl", function($scope) {
  $scope.msg = "grapecity team blog"
  })
  // add a filter
  myApp.filter("myUpperFilter", function() {
  return function(input) {
  return input.toUpperCase()
  }
  })
  // add a directive
  myApp.directive("myDctv", function() {
  return function(scope, element, attrs) {
  element.bind("mouseenter", function() {
  element.css("background", "yellow")
  })
  element.bind("mouseleave", function() {
  element.css("background", "none")
  })
  }
  })

  上面示例中module 方法的第一个参数为模块的名称,第二个参数为它的依赖模块列表。我们创建了一个独立的模块,不依赖于其它模块。所以第二个参数为空数组(注意:即使它为空,我们也必须填写这个参数。否则,该方法回去检索之前的同名模块)。

最新文章