最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Angularjs基礎(chǔ)知識(shí)及示例匯總

 更新時(shí)間:2015年01月22日 09:52:35   投稿:hebedich  
本文給大家總結(jié)了一些angularjs的基礎(chǔ)知識(shí)及相關(guān)示例,分享給大家,希望能對(duì)大家有所幫助。

angularjs是google開發(fā)的一款高大上的前端mvc開發(fā)框架。

Angularjs官網(wǎng):https://angularjs.org/ 官網(wǎng)有demo,訪問(wèn)可能需要FQ

Angularjs中國(guó)社區(qū):http://www.angularjs.cn/ 適合初學(xué)者

引用文件:https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js

使用angular注意

引用angularjs庫(kù):https://github.com/litengdesign/angularjsTest/blob/master/angular-1.0.1.... 可以在本節(jié)示例的github上下載
需要在你使用的區(qū)域加上ng-app="appName",或者直接ng-app(全局)。
設(shè)置控制器 ng-controller="Ctrl"。
測(cè)試一下示例請(qǐng)注意以下幾點(diǎn)

需要在head之前引入angularjs代碼,作者使用的是angular-1.0.1.min.js,請(qǐng)注意版本區(qū)別。
所有小示例都是在以下區(qū)域運(yùn)行,記得在作用區(qū)域加上 ng-app。
下面通過(guò)一些小的案例來(lái)說(shuō)明angularjs默認(rèn)的常見的指令和用法。

hello world程序(雙數(shù)據(jù)綁定)

使用ng-model={{name}}來(lái)綁定數(shù)據(jù)

復(fù)制代碼 代碼如下:

<label for="name">name:</label>
<input type="text" ng-model="name" id="name"/>
<hr>
hello:{{name || 'liteng'}}

 http://2.liteng.sinaapp.com/angularjsTest/helloangularjs.html

事件綁定使用小案例

復(fù)制代碼 代碼如下:

<div>
  單價(jià):<input type="number" min=0 ng-model="price" ng-init="price=299">
  數(shù)量: <input type="number" min=0 ng-model="quantity" ng-init="quantity=1">  
  <br>
  總價(jià):{{(price) * (quantity)}}
  <dt>
    <dl>注:</dl>
    <dd>涉及html5的input:<a href=">
    <dd>ng-init:設(shè)定初始值</dd>
  </dt>
</div>

 http://2.liteng.sinaapp.com/angularjsTest/event-bind.html

ng-init:可默認(rèn)指定屬性值

復(fù)制代碼 代碼如下:

<p ng-init="value='hello world'">{{value}}</p>

 http://2.liteng.sinaapp.com/angularjsTest/ng-init.html

ng-repeat:用于迭代數(shù)據(jù)類似于js中的 i for info

復(fù)制代碼 代碼如下:

<div ng-init="friends=[{name:'Jhon',age:25},{name:'Mary',age:28}]"></div>
  <p>我有{{friends.length}} 朋友.他們是</p>
  <ul>
    <li ng-repeat="friend in friends">
      [{{$index+1}}]:{{friend.name}}年齡為:{{friend.age}}
    </li>
   </ul>

 http://2.liteng.sinaapp.com/angularjsTest/ng-repeat.html

ng-click:dom的點(diǎn)擊事件

復(fù)制代碼 代碼如下:

<div ng-controller="ctrl">
  <button ng-dblclick='showMsg()'>{{a}}</button>
</div>
<script>
    function ctrl($scope){
      $scope.a='hello';
      $scope.showMsg=function(){
        $scope.a='world';
      }
     }
  </script>

 http://2.liteng.sinaapp.com/angularjsTest/ng-click.html

ng-show:設(shè)置元素顯示

注:ng-show="!xx":在屬性值前面加!表示確定顯示,如果不加!表示不確定則不顯示

復(fù)制代碼 代碼如下:

<div ng-show="!show">
  ng-show="!show"
</div>
<div ng-show="show">
  ng-show="show"
</div>

 http://2.liteng.sinaapp.com/angularjsTest/ng-show.html

ng-hide:設(shè)置元素隱藏

復(fù)制代碼 代碼如下:

<div ng-hide="aaa">
  ng-hide="aaa"
</div>
<div ng-hide="!aaa">
  ng-show="!aaa"
</div>

 http://2.liteng.sinaapp.com/angularjsTest/ng-hide.html

運(yùn)用ng-show制作toggle效果

復(fù)制代碼 代碼如下:

<h2>toggle</h2>
  <a href ng-click="showLog=!showLog">顯示logo</a>
  <div ng-show="showLog">
    <img ng-src="   </div>

 http://2.liteng.sinaapp.com/angularjsTest/ng-toggle.html

ng-style:和默認(rèn)style類似

這里請(qǐng)注意書寫格式:字符串需要用引號(hào)包含

復(fù)制代碼 代碼如下:

<div ng-style="{width:100+'px',height:200+'px',backgroundColor:'red'}">
  box
</div>

 http://2.liteng.sinaapp.com/angularjsTest/ng-style.html

filter:過(guò)濾字段

復(fù)制代碼 代碼如下:

<div>{{9999|number}}</div> <!--9,999-->
<div>{{9999+1 |number:2}}</div><!--10,000.00-->
<div>{{9*9|currency}}</div><!--$81.00-->
<div>{{'hello world' | uppercase}}</div><!--HELLO WORLD-->

 http://2.liteng.sinaapp.com/angularjsTest/filter.html

ng-template:可以加載模板

復(fù)制代碼 代碼如下:

<div ng-include="'tpl.html'"></div>

 tpl.html

復(fù)制代碼 代碼如下:

<h1>hello</h1>

 http://2.liteng.sinaapp.com/angularjsTest/show-tpl.html

$http:一個(gè)類似ajax的方法很管用

復(fù)制代碼 代碼如下:

<div class="container" ng-controller="TestCtrl">
  <h2>HTTP請(qǐng)求-方法1</h2>
    <ul>
        <li ng-repeat="x in names">
        {{x.Name}}+{{x.Country}}
        </li>
    </ul>
</div>
<h2>方法2</h2>
  <div ng-controller="TestCtrl2">
     <ul>
        <li ng-repeat="y in info">
            {{y.aid}}+{{y.title}}
        </li>
     </ul>
</div>
<script>
//方法1
      var TestCtrl=function($scope,$http){
         var p=$http({
            method:'GET',
            url:'json/date.json'
         });
         p.success(function(response,status,headers,config){
            $scope.names=response;
         });
         p.error(function(status){
            console.log(status);
         });
      }
      //方法2
      function TestCtrl2($scope,$http){
        $http.get('json/yiqi_article.json').success(function(response){
             $scope.info=response;
        });
      }
</script>

 http://2.liteng.sinaapp.com/angularjsTest/ajax.html

以上所有的code:https://github.com/litengdesign/angularjsTest

實(shí)現(xiàn)的demo:http://2.liteng.sinaapp.com/angularjsTest/index.html

至于angularjs的路由(router)和指令(directive)下次本人將單獨(dú)拿出來(lái)講。

相關(guān)文章

  • 詳解Angular中的自定義服務(wù)Service、Provider以及Factory

    詳解Angular中的自定義服務(wù)Service、Provider以及Factory

    本篇文章主要介紹了詳解Angular中的自定義服務(wù)Service、Provider以及Factory,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Angularjs CURD 詳解及實(shí)例代碼

    Angularjs CURD 詳解及實(shí)例代碼

    這篇文章主要介紹了Angularjs CURD 詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • 基于angular實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)的生日插件

    基于angular實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)的生日插件

    這篇文章主要為大家詳細(xì)介紹了基于angular實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)的生日插件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • AngularJS實(shí)現(xiàn)在ng-Options加上index的解決方法

    AngularJS實(shí)現(xiàn)在ng-Options加上index的解決方法

    這篇文章主要介紹了AngularJS實(shí)現(xiàn)在ng-Options加上index的解決方法,結(jié)合實(shí)例形式分析了AngularJS在ngOptions添加索引的操作步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-11-11
  • Angular短信模板校驗(yàn)代碼

    Angular短信模板校驗(yàn)代碼

    這篇文章主要介紹了Angular短信模板校驗(yàn)代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Angular2使用Angular-CLI快速搭建工程(二)

    Angular2使用Angular-CLI快速搭建工程(二)

    這篇文章主要介紹了Angular2使用Angular-CLI快速搭建工程(二),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 詳解Angular依賴注入

    詳解Angular依賴注入

    依賴注入(DI -- Dependency Injection)是一種重要的應(yīng)用設(shè)計(jì)模式。Angular里面也有自己的DI框架,在設(shè)計(jì)應(yīng)用時(shí)經(jīng)常會(huì)用到它,它可以我們的開發(fā)效率和模塊化程度。&#160;Angular系統(tǒng)中通過(guò)在類上添加@Injectable裝飾器來(lái)告訴系統(tǒng)這個(gè)類(服務(wù))是可注入的。
    2021-05-05
  • AngularJS入門教程之學(xué)習(xí)環(huán)境搭建

    AngularJS入門教程之學(xué)習(xí)環(huán)境搭建

    這篇文章主要介紹了AngularJS入門教程之學(xué)習(xí)環(huán)境搭建,本教程將指導(dǎo)您完成一個(gè)簡(jiǎn)單的應(yīng)用程序創(chuàng)建過(guò)程,包括編寫和運(yùn)行單元測(cè)試、不斷地測(cè)試應(yīng)用,需要的朋友可以參考下
    2014-12-12
  • AngularJS 中的事件詳解

    AngularJS 中的事件詳解

    本文主要介紹AngularJS 事件,這里整理了相關(guān)資料,比較詳細(xì)的介紹了AngularJS的使用方法,有需要的小伙伴參考下
    2016-07-07
  • 詳解JavaScript的AngularJS框架中的作用域與數(shù)據(jù)綁定

    詳解JavaScript的AngularJS框架中的作用域與數(shù)據(jù)綁定

    這篇文章主要介紹了JavaScript的AngularJS框架中的作用域與數(shù)據(jù)綁定,包括作用域的繼承以及數(shù)據(jù)的單向和雙向綁定等重要知識(shí)點(diǎn),需要的朋友可以參考下
    2016-03-03

最新評(píng)論

景德镇市| 盐津县| 防城港市| 新沂市| 平遥县| 隆德县| 博客| 上栗县| 吐鲁番市| 当雄县| 榆树市| 宾阳县| 天长市| 宁南县| 密云县| 乐业县| 金溪县| 旺苍县| 马关县| 伊通| 扎赉特旗| 郑州市| 老河口市| 八宿县| 南木林县| 长岭县| 桐庐县| 盈江县| 专栏| 彰化市| 红安县| 株洲县| 永顺县| 耒阳市| 原阳县| 洪湖市| 上虞市| 长岭县| 疏勒县| 遵义县| 望江县|