码迷,mamicode.com
首页 > 其他好文 > 详细

part 2 Angular modules and controllers

时间:2015-12-09 01:48:36      阅读:124      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!