Cordova學習筆記 angular 中一些標籤的使用

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
    <style>
            .red{
                background-color: red;
            }
           .black{
               background-color: black;
           }
    </style>
    <script src="js/angular.js"></script>
    <script type="application/javascript">
        (function(angular) {
            'use strict';
            angular.module('myApp', [])
                    .controller('firstController', function firstController($scope,$sce) {
                        $scope.witchColor = {red:true,black:false};
                        $scope.changeColor = function(){
                            if($scope.witchColor.red){
                                $scope.witchColor.red = false;
                            }else{
                                $scope.witchColor.red = true;
                            }

                            if($scope.witchColor.black){
                                $scope.witchColor.black = false;
                            }else{
                                $scope.witchColor.black = true;
                            }
                        }
                        $scope.teststyle={color:'yellow'};
                        $scope.address= "http://www.baidu.com";
                        $scope.idshow = true;
                        $scope.idshow = false;
                        $scope.mySwitch = 3;
                        $scope.t1 = "test1";
                        $scope.t2 = "test2";
                        $sce.trustAsHtml("<a href='http://benohead.com'>benohead.com</a>");
                        $scope.myhtml1= $sce.trustAsHtml("<a href='http://benohead.com'>benohead.com</a>");//$sce 中的trustAsHtml來信任這個html內容
                    });

        })(window.angular);//主模塊

        window.onload = function(){
            var myAppdiv = document.getElementById('myApp22');
            angular.bootstrap(myAppdiv,['myApp']) //動態的綁定主mudule的html作用範圍
        }
    </script>
</head>
<body >
<div id="myApp22">
    <div ng-controller="firstController">
            <div ng-class="witchColor">test</div>
        <input type="button" value="changeColor" ng-click="changeColor()"/>
        <div ng-style="teststyle">test</div>
        <a ng-href="`address`">www</a>
        <div ng-show="idshow">您</div>
        <div ng-switch on="mySwitch">
            <span ng-switch-default> 0</span>
            <span ng-switch-when="1">1</span>
            <span ng-switch-when="2">2</span>
            <span ng-switch-when="3">3</span>
        </div>
        <div ng-bind-template="`t1``t2`"></div><!--綁定多個-->
        <div ng-bind-html="myhtml1" >1212</div> <!--把這個div中的innerHtml綁定到變量myhtml-->
    </div>
</div>
</body>
</html>


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