ng-class、ng-style、ng-href、ng-attr-title

在angularjs中,設置樣式:

   <style>
        .red{
            background: red;
        }
        .yellow{
            background: yellow;
        }

        div a {
            text-decoration: none;
        }

    </style>
    <script src="js/angular.min.js"></script>
    <script>
        var app = angular.module("myApp",[]);
        app.controller("myCtrl", function($scope){
            $scope.text = "hello";
            $scope.sClass = "{red:true}";
            //$scope.url = "http://www.baidu.com";
            $scope.url = "http://www.baidu.com";
        })
    </script>
<div ng-controller="myCtrl">
        <div ng-class="{{sClass}}">{{text}}</div>
        <div ng-class="{red:true,yellow:true}">{{text}}</div>
        <div ng-style="{background:'red',color:'white'}">{{text}}</div>
        <div>
            <a ng-href="{{url}}">aaaaa</a><br/>
            <a ng-attr-href="{{url}}" ng-attr-title="{{text}}" ng-attr-class="" ng-attr-style="">aaaaa</a>
        </div>
    </div>
樣式如下:


點擊aaa,可鏈接到百度;把鼠標箭頭放到第二個aaa上,會出現標題“hello”;

注意:在angular中用ng-class設置內部樣式時,樣式格式爲:  如:ng-class="{red:true}",後面有個true;

外部樣式與class類似;

用ng-style設置樣式時,與style沒什麼大的區別


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章