angularJS日志

1.ng-app 指令定義一個(gè) AngularJS 應(yīng)用程序。
2.ng-model 指令把元素值(比如輸入域的值)綁定到應(yīng)用程序。
3.ng-bind 指令把應(yīng)用程序數(shù)據(jù)綁定到 HTML 視圖。
4.AngularJS 表達(dá)式寫在雙大括號(hào)內(nèi):{{ expression }}

  <div ng-app="">
    <input type="text" ng-model="name">
    <p>hello {{name}}</p>
  </div>

5.ng-init 指令初始化 AngularJS 應(yīng)用程序變量。

  <div ng-app="" ng-init="name='world'">
    <input type="text" ng-model="name">
    <p>hello {{name}}</p>
  </div>

6.AngularJS 模塊(Module) 定義了 AngularJS 應(yīng)用。
7.AngularJS 控制器(Controller) 用于控制 AngularJS 應(yīng)用。

  <div ng-app="test" ng-controller="testCtl">
    <input type="text">
    <p>{{firstName + " " + lastName}}</p>
  </div>
  <script type="text/javascript">
    //聲明模塊
    var app=angular.module('test',[]);
    //聲明控制器
    app.controller('testCtl',function($scope){
        $scope.firstName="hello";
        $scope.lastName="world";
    })
  </script>

8.ng-repeat 指令會(huì)重復(fù)一個(gè) HTML 元素

  <div ng-app="test" ng-controller="testCtl">
    <ul>
        <li ng-repeat="x in arr">{{x}}</li>
    </ul>
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope){
        $scope.arr=[1,2,3,4,5,6];
    })
  </script>

9.使用 .directive 函數(shù)來(lái)添加自定義的指令,使用駝峰法來(lái)命名一個(gè)指令, testDirective, 但在使用它時(shí)需要以 - 分割, test-directive,你可以通過(guò)以下方式來(lái)調(diào)用指令:
a.元素名 b.屬性 c.類名 d.注釋
通過(guò)添加 restrict 屬性,可以限制自定義指令只能通過(guò)特定的方式來(lái)調(diào)用,可以通過(guò)以下方式來(lái)調(diào)用指令:
a.元素名("A") b.屬性("E") c.類名("C") d.注釋("M)

  <div ng-app="test">
    <test-directive></test-directive>
    <div test-directive></div>
    <div class="test-directive"></div>
    <!-- 指令:test-directive -->
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.directive("testDirective",function(){
        return {
            restrict:"ACEM",
            template:"<h1>自定義的指令</h1>"
        };
    })
  </script>

10.在ng-show屬性返回 true的情況下顯示,返回false隱藏。

  <div ng-app="">
    <p ng-show="true">顯示信息</p>
  </div>

11.$scope作用在當(dāng)前控制器作用域中,$rootScope作用在整個(gè)應(yīng)用程序作用域中,$rootScope常用作各個(gè)控制器的連接與通信
12.使用一個(gè)管道字符(|) 過(guò)濾數(shù)據(jù),常用的過(guò)濾器有:

過(guò)濾器 描述
currency 格式化數(shù)字為貨幣格式
filter 從數(shù)組項(xiàng)中選擇一個(gè)子集
lowercase 格式化字符串為小寫
orderBy 根據(jù)某個(gè)表達(dá)式排列數(shù)組
uppercase 格式化字符串為大寫
  <div ng-app="test" ng-controller="testCtl">
    {{ firstName | uppercase}}
    {{ lastName | lowercase}}
    {{ price | currency}}
    <ul>
        <li ng-repeat="x in names | filter:'test2' | orderBy:'country'">{{x.name + " " + x.country}}</li>
    </ul>
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope){
        $scope.firstName="hello";
        $scope.lastName="WORLD";
        $scope.price="1234";
        $scope.names=[{name:"test1",country:"wuhan"},{name:"test2",country:"shanghai"},{name:"test3",country:"shenzhen"}]
    })
  </script>

13.$location.absUrl()返回當(dāng)前頁(yè)面的地址

  <div ng-app="test" ng-controller="testCtl">
    {{url}}
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope,$location){
        $scope.url=$location.absUrl();
    })
  </script>

14.$http服務(wù)發(fā)起服務(wù)器請(qǐng)求

  <div ng-app="test" ng-controller="testCtl">
    <h1>{{value}}</h1>
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope,$http){
        $http.get("test.json").success(function(response){
            $scope.value=response.key;
        });
    })
  </script>

15.$timeout 對(duì)應(yīng)了 JS window.setTimeout 函數(shù)

  <div ng-app="test" ng-controller="testCtl">
    {{info}}
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope,$timeout){
        $scope.info="hello world";
        $timeout(function(){
                $scope.info="how are you today";
            },3000)
    })
  </script>

16.$interval 對(duì)應(yīng)了 JS window.setInterval 函數(shù)

  <div ng-app="test" ng-controller="testCtl">
    {{info}}
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope,$interval){
        $scope.info=new Date().toLocaleString();
        $interval(function(){
                $scope.info=new Date().toLocaleString();
            },1000)
    })
  </script>

17.使用.service創(chuàng)建自定義服務(wù)

  <div ng-app="test" ng-controller="testCtl">
    {{info}}
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope,test){
        $scope.info=test.myFunc(1000);
    })
    app.service('test',function(){
        this.myFunc=function(x){
            return x.toString(16)
        }
    })
  </script>

18.ng-options 指令創(chuàng)建下拉列表

  <div ng-app="test" ng-controller="testCtl">
    <select ng-options="x for x in names" ng-model="selectName"></select>
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope){
        $scope.selectName="wuhan";
        $scope.names=["wuhan","sandong","shanghai","shenzhen"]
    })
  </script>

19.$index表示循環(huán)中的序號(hào)

  <div ng-app="test" ng-controller="testCtl">
    <ul>
        <li ng-repeat="x in names">{{ $index }}</li>
    </ul>
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope){
        $scope.names=["wuhan","sandong","shanghai","shenzhen"]
    })
  </script>

20.$odd$even分別表示序號(hào)奇數(shù)和偶數(shù)位
21.ng-disabled 指令綁定數(shù)據(jù)到 HTML 的 disabled 屬性。

  <div ng-app="test" ng-controller="testCtl">
    <button ng-disabled="mySwitch">點(diǎn)擊</button>
    <input type="checkbox" ng-model="mySwitch">按鈕
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope,$http){
        $scope.mySwitch=true;
    })
  </script>

22.ng-hide 指令用于隱藏或顯示 HTML 元素。
23.ng-click 指令定義了點(diǎn)擊事件。

  <div ng-app="test" ng-controller="testCtl">
    <button ng-click="count=count+1">點(diǎn)擊</button>
    <h1>{{count}}</h1>
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope,$http){
        $scope.count=0;
    })
  </script>

24.ng-include在HTML頁(yè)面中包含HTML頁(yè)面

  <div ng-app="test" ng-controller="testCtl">
    <div ng-include="'module.html'"></div>
  </div>
  <script type="text/javascript">
    var app=angular.module('test',[]);
    app.controller('testCtl',function($scope){  

    })
  </script>

25.angular.bind(object,function(){},arguments)動(dòng)態(tài)綁定
26.angular.bootstrap(element,['module'])手動(dòng)加載模塊
27.angular.copy復(fù)制一個(gè)對(duì)象
28.angular.element()返回一個(gè)jQuery對(duì)象
29.angular.equals()比較兩個(gè)對(duì)象是否相等
30.angular.forEach(obj,function(value,key){})迭代
31.angular.fromJson(string)將json字符串轉(zhuǎn)換為json對(duì)象

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,250評(píng)論 6 530
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 97,923評(píng)論 3 413
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人,你說(shuō)我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,041評(píng)論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我,道長(zhǎng),這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,475評(píng)論 1 308
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 71,253評(píng)論 6 405
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 54,801評(píng)論 1 321
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 42,882評(píng)論 3 440
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,023評(píng)論 0 285
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 48,530評(píng)論 1 331
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 40,494評(píng)論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 42,639評(píng)論 1 366
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,177評(píng)論 5 355
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 43,890評(píng)論 3 345
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,289評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,552評(píng)論 1 281
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 51,242評(píng)論 3 389
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 47,626評(píng)論 2 370

推薦閱讀更多精彩內(nèi)容