首页 > 其他 > 详细

part 2 Angular modules and controllers

时间:2015-12-09 01:45:30      阅读:214      评论:0      收藏:0      [点我收藏+]

What is a module in AngularJS?

A module is a container for different parts of your application i.e controllers,services,directives,filters,etc.

You can think of a module as a Main() method in other types of applications.

How to create a module?

Use the angular object‘s module() method to create a module.

var myApp = angular.module("myModule",[]);//the first parameter specify the name of module,the second parameter specify the dependence for the module,here i just set an empty array. 

What is a controller in angular?

In angular a controller is a JavaScript function. The job of the controller is to build a model for the view to display.

How to create a controller in angular?

var myController = function($scope){
    $scope.message="AngularJS Tutorial";    
};

How to register the controller with the module?

myApp.controller("myController",myController);           //  1 way
myApp.controller("myController",function($scope){       // 2 way
    $scope.message="AngularJS Tutorial";    
});

技术分享

In js file , we can add a reference with angular.js to has some code tip.(autocomplete some angular member.)

part 2 Angular modules and controllers

原文:http://www.cnblogs.com/gester/p/5031573.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!