欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

AngularJS的一些基本樣式初窺

 更新時間:2015年07月27日 17:43:57   作者:humingx  
這篇文章主要介紹了AngularJS的一些基本樣式初窺,AngularJS是一款高人氣JavaScript框架,需要的朋友可以參考下

顯示和隱藏

在 Angular 中的一切,都是基于模型的改變,進(jìn)而通過標(biāo)識符反映這些變化到界面上。
ng-show 和 ng-hide 可以做相同的事情。顯示和隱藏是基于你傳遞給他們的表達(dá)式而定,即,當(dāng)表達(dá)式為 true 時,ng-show 就顯示,反之隱藏。當(dāng)表達(dá)式為 true 時,ng-hide 就隱藏,反之顯示。這些標(biāo)識符是通過設(shè)置元素的樣式 display:block 顯示和 display:none 隱藏進(jìn)行工作的。
CSS類和樣式

通過 {{}} 解析來進(jìn)行數(shù)據(jù)綁定,從而能夠動態(tài)地設(shè)置類和樣式。
ng-class 和 ng-style

在大型項目中,上面的方式會使得難以管理,以至于不得不同時閱讀模版和 JavaScript 才能正確地創(chuàng)建 css 。
Angular 提供了 ng-class 和 ng-style 標(biāo)識符。他們每一個都需要一個表達(dá)式。表達(dá)式執(zhí)行的結(jié)果可能是下列之一:

  •     一個字符串,表示空間隔開的類名。
  •     一個類名數(shù)組
  •     一個類名到布爾值的映射

選中的行

模版中,我們設(shè)置 ng-class 的值為 {selected:$index==selectedRow},當(dāng)模型調(diào)用selectedRow 時將匹配 ng-repeat 的 $index,進(jìn)而顯示選中的樣式。同樣我們設(shè)置 ng-click 來通知控制器用戶點了哪一行。
src 和 href 建議

建議使用 ng-src 和 ng-href。

<img ng-src="/img/01.png">
<a ng-href="www.segmentfault.com">segmentfault</a>

所有源碼

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>angular demo</title>
  <script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.8/angular.min.js"></script>
</head>
<body>
  <div id="App1" ng-app="shoppingCart" ng-controller="ShoppingCartController">
    <h1>Your demo</h1>
    <!-- demo 1 -->
    <div ng-show='menuState.show'>another another another</div>
    <button ng-click="test2()">切換</button>

    <hr><!-- demo 2 -->
    <style type="text/css">
      .menu-disabled-true{
        opacity:1;
        color: red;
        -webkit-transition:all 1000ms linear;
        -moz-transition:all 1000ms linear;
        -o-transition:all 1000ms linear;
      }
      .menu-disabled-false{
        opacity: 0;
        -webkit-transition:all 1000ms linear;
        -moz-transition:all 1000ms linear;
        -o-transition:all 1000ms linear;
      }
    </style>
    <div class="menu-disabled-{{isDisabled}}">adfadfadasda</div>
    <button ng-click="test()">隱藏</button>
    <button ng-click="test1()">顯示</button>
    <button ng-click="test11()">切換</button>

    <hr><!-- demo 3 -->
    <style type="text/css">
    .error {
      background-color: red;
    }
    .warning {
      background-color: yellow;
    }
    </style>
    <div ng-class='{error:isError, warning:isWarning}'>{{messageText}}</div>
    <button ng-click="showError()">error</button>
    <button ng-click="showWarning()">warning</button>

    <hr><!-- demo 4 -->
    <style type="text/css">
      .selected{
        background-color: lightgreen;
      }
    </style>
    <div ng-repeat="item in items" ng-class='{selected:$index==selectedRow}' ng-click='selectedWhich($index)'>
      <span>{{item.product_name}}</span>
      <span>{{item.price | currency}}</span>
    </div>
  </div>

  <script>
    var shoppingCartModule = angular.module("shoppingCart", [])
    shoppingCartModule.controller("ShoppingCartController",
      function ($scope) {
        // demo 1
        $scope.menuState = {'show':true};
        $scope.test2 = function () {
          $scope.menuState.show = !$scope.menuState.show;
        };

        // demo 2
        $scope.isDisabled = true;
        $scope.test = function () {
          $scope.isDisabled = 'false';
        };
        $scope.test1 = function () {
          $scope.isDisabled = 'true';
        };
        $scope.test11 = function () {
          $scope.isDisabled = !$scope.isDisabled;
        };

        // demo 3
        $scope.isError = false;
        $scope.isWarning = false;
        $scope.messageText = 'default, default';
        $scope.showError = function () {
          $scope.messageText = 'This is an error';
          $scope.isError = true;
          $scope.isWarning = false;
        };
        $scope.showWarning = function () {
          $scope.messageText = 'Just a warning, donot warry';
          $scope.isWarning = true;
          $scope.isError = false;
        };

        // demo 4
        $scope.items = [
          { product_name: "Product 1", price: 50 },
          { product_name: "Product 2", price: 20 },
          { product_name: "Product 3", price: 180 }
        ];
        $scope.selectedWhich = function (row) {
          $scope.selectedRow = row;
        }
      }
    );
  </script>
</body>
</html>

相關(guān)文章

  • Angular1.x自定義指令實例詳解

    Angular1.x自定義指令實例詳解

    這篇文章主要介紹了Angular1.x自定義指令,結(jié)合實例形式分析了Angular1.x自定義指令的實現(xiàn)與使用方法,以及相關(guān)操作技巧與注意事項,需要的朋友可以參考下
    2017-03-03
  • AngularJS仿蘋果滑屏刪除控件

    AngularJS仿蘋果滑屏刪除控件

    前端開發(fā)中,為了對列表項進(jìn)行快捷操作,有時就添個按鈕來簡單實現(xiàn)。但是,有時會發(fā)現(xiàn)按鈕影響美觀,甚至影響列表行的布局。稍在網(wǎng)上搜索無果,而寫此仿蘋果滑屏刪除控件
    2016-01-01
  • 如何處理Angular?錯誤消息ERROR?Error?NullInjectorError?No?provider?for?XX

    如何處理Angular?錯誤消息ERROR?Error?NullInjectorError?No?provid

    這篇文章主要介紹了如何處理Angular?錯誤消息ERROR?Error?NullInjectorError?No?provider?for?XX
    2023-07-07
  • Angular環(huán)境搭建及簡單體驗小結(jié)

    Angular環(huán)境搭建及簡單體驗小結(jié)

    Angular基于TypeScript和react、vue相比 Angular更適合中大型企業(yè)級項目,本文通過實例代碼給大家分享Angular環(huán)境搭建及簡單體驗,感興趣的朋友跟隨小編一起學(xué)習(xí)吧
    2021-05-05
  • AngularJS ng-bind-template 指令詳解

    AngularJS ng-bind-template 指令詳解

    本文注意介紹AngularJS ng-bind-template 指令,這里把相關(guān)資料整理了一下,并附實例代碼,有需要的小伙伴可以參考下
    2016-07-07
  • AngularJS獲取json數(shù)據(jù)的方法詳解

    AngularJS獲取json數(shù)據(jù)的方法詳解

    這篇文章主要介紹了AngularJS獲取json數(shù)據(jù)的方法,結(jié)合實例形式詳細(xì)分析了AngularJS獲取json數(shù)據(jù)的詳細(xì)步驟、操作技巧與相關(guān)注意事項,需要的朋友可以參考下
    2017-05-05
  • AngularJs ng-route路由詳解及實例代碼

    AngularJs ng-route路由詳解及實例代碼

    這篇文章主要介紹了AngularJs ng-route路由,這里整理相關(guān)資料及簡單實例代碼,有興趣的小伙伴可以參考下
    2016-09-09
  • Angularjs使用過濾器完成排序功能

    Angularjs使用過濾器完成排序功能

    這篇文章主要為大家詳細(xì)介紹了Angularjs使用過濾器完成排序功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • 詳解angular如何調(diào)用HTML字符串的方法

    詳解angular如何調(diào)用HTML字符串的方法

    這篇文章主要介紹了詳解angular如何調(diào)用HTML字符串的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • Angular Excel 導(dǎo)入與導(dǎo)出的實現(xiàn)代碼

    Angular Excel 導(dǎo)入與導(dǎo)出的實現(xiàn)代碼

    這篇文章主要介紹了Angular Excel 導(dǎo)入與導(dǎo)出的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-04-04

最新評論