AngularJs初接触

        虽然是java开发,但是总会接触到一些前端的知识,以前做Web只是和Jsp打交道,但是看到了Angularjs,感觉理念很好,感觉很有新鲜感。。。

被称为前端的MVC(Model-view-Controller)

        感觉学习任何一个新的知识点,helloworld永远是不变的起点,今天我就用helloworld来开始我的AngularJs的学习之路。。。

        

以下是我按照案例写的一个HelloWorld的案例:

    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
< html  ng-app = 'helloApp' >
     < head >
         < meta  charset = "utf-8" >
         < title >AngularHello</ title >
         < script  type = "text/javascript"  src = "../js/angular/angular.js" ></ script >
         < script  type = "text/javascript"  src = "../js/angularDemo/controller.js" ></ script >
     </ head >
     < body >
             < div  ng-controller = 'Hello' >
                 < input  ng-model = "greeting.text"  />
                 < p >< span  ng-bind = "greeting.text" ></ span >< span >,world</ span ></ p >
             </ div >
     </ body >
</ html >


controller.js如下

1
2
3
4
5
var  helloApp = angular.module( "helloApp" ,[]);
 
helloApp.controller( "Hello" function ($scope) {
     $scope.greeting = {text: 'hello' };
});


运行结果如下:




没有什么dom操作,什么都没有做就可以将值绑定在上面了,是不是很神奇呢.........

猜你喜欢

转载自blog.csdn.net/u012889214/article/details/50181153