您的位置:首页 > Web前端 > AngularJS

Angularjs初识及其特性

2016-10-12 22:03 274 查看
Angularjs是一个javascript框架,其特点:

1,MVC模型    2,模块化   3,指令系统     4,双向数据绑定

一,MVC框架

   实例演示:两个文件(html和js)

    html中:<html ng-app>

             ..<div ng-controller="helloAngular">    //controller在js中实现

                    <p>{{hello}},cyan</p>            //实现view,{{}}实现module

               </div>

             ..引入angularjs文件和js文件

    js中:function helloAngular($scope){

            $scope.hello={

               text:'hello'

                };

            }
二,模块化

   实例演示:两个文件(html和js)

    html中:<html ng-app="myModule">            //写module名

             ..<div ng-controller="helloAngular">    

                    {{hello}},cyan            

               </div>

             ..引入angularjs文件和js文件

    js中: var mymodule=angular.Module("myModule",[]);          //定义module

            mymodule.controller("helloAngular"['$scope',

            function helloAngular($scope){

            $scope.hello={

               text:'hello'

                };

            }])
三,标签系统

   实例演示:两个文件(html和js)

    html中:<html ng-app="myModule">            

             ..<hello></hello>                     //使用标签

             ..引入angularjs文件和js文件

    js中: var mymodule=angular.Module("myModule",[]);          //定义module

            mymodule.derictive("hello",function(){                //定义标签

            return{

               rescrict:'E',

               template:'<div>hello ,cyan</div>',

               replace:true

                };

            }])
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: