亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

angularjs中ng-attr的用法詳解

 更新時(shí)間:2016年12月31日 09:53:08   作者:冰果在線  
這篇文章主要給大家介紹了angularjs中ng-attr的用法,文中通過(guò)實(shí)例代碼介紹的很詳細(xì),有需要的朋友可以參考借鑒,下面來(lái)一起看看吧。

前言

html中的屬性很多,同樣可以使用angularjs來(lái)定義:

ng-attr-(suffix)=只能使用變量定義

<div title="angularjs中的title">title</div>
<div ng-attr-title="angularjs中的title">title</div><!--這樣寫(xiě)顯示不出來(lái)標(biāo)題-->
<div ng-attr-title="'angularjs中的title'">title</div><!--這樣寫(xiě)顯示不出來(lái)標(biāo)題-->
<div ng-attr-title="{{titleStr}}">title</div><!--只能使用變量定義-->
angular.module('myApp',[])
   .controller('myCtrl',['$scope',function($scope){
       $scope.titleStr = "angularjs中的title";
   }]);

ng-bind中使用字符可以將文字顯示出來(lái)

<span ng-bind=" 'angularjs中的title'  ";

用法實(shí)例代碼:

<!DOCTYPE html>
<html lang="zh-CN" ng-app="app">
<head>
  <meta charset="utf-8">
  <title>ng-attr-(suffix)的用法</title>
  <link rel="stylesheet" href="../bootstrap.min.css">
</head>
<body>
  <div>
    <p>1.正確做法:</p>
    <input type="text" ng-model="suffix" placeholder="請(qǐng)輸入input的type值">
    (如:checkbox,radio,button,submit...)
    <br><br>
    我將隨著輸入的值變化:<input ng-attr-type="{{ suffix }}"> 
  </div>
  <div style="margin-top: 20px;">
    <p>2.錯(cuò)誤做法:cx="{{ cx }}"</p>
    <p>這里的錯(cuò)誤做法,并非真正的錯(cuò)誤做法,只是有時(shí)瀏覽器會(huì)對(duì)屬性會(huì)進(jìn)行很苛刻的限制,所以不建議這樣做。比如svg</p>
    <div style="border: 1px solid red;width: 200px;height: 200px;">
      <svg>   
        <circle cx="{{ cx }}"></circle> 
      </svg> 
      這里瀏覽器會(huì)報(bào)錯(cuò) 
    </div>
    
    改為:ng-attr-cx="{{ cx }}"
    <div style="border: 1px solid green;width: 200px;height: 200px;">
      <svg>   
        <circle ng-attr-cx="{{ cx }}"><circle>
      </svg>
      這里不會(huì)報(bào)錯(cuò)
    </div>
    
  </div>
  

  
  <script src="../angular.min.js"></script>
  <script>
    angular.module('app', [])
  </script>
</body>
</html>

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流。

相關(guān)文章

最新評(píng)論