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

angularjs中ng-attr的用法詳解

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

前言

html中的屬性很多,同樣可以使用angularjs來定義:

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

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

ng-bind中使用字符可以將文字顯示出來

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

用法實例代碼:

<!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="請輸入input的type值">
    (如:checkbox,radio,button,submit...)
    <br><br>
    我將隨著輸入的值變化:<input ng-attr-type="{{ suffix }}"> 
  </div>
  <div style="margin-top: 20px;">
    <p>2.錯誤做法:cx="{{ cx }}"</p>
    <p>這里的錯誤做法,并非真正的錯誤做法,只是有時瀏覽器會對屬性會進行很苛刻的限制,所以不建議這樣做。比如svg</p>
    <div style="border: 1px solid red;width: 200px;height: 200px;">
      <svg>   
        <circle cx="{{ cx }}"></circle> 
      </svg> 
      這里瀏覽器會報錯 
    </div>
    
    改為:ng-attr-cx="{{ cx }}"
    <div style="border: 1px solid green;width: 200px;height: 200px;">
      <svg>   
        <circle ng-attr-cx="{{ cx }}"><circle>
      </svg>
      這里不會報錯
    </div>
    
  </div>
  

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

總結(jié)

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

相關(guān)文章

最新評論