AngularJS 指令(使瀏覽器認識本身定義的標籤)

     對於angular js還有其強大之處,能夠利用angular js的指令來自定義許多標籤。下面是一個實例:app

自定一個名爲hello標籤,視圖以下:spa

<div ng-app="myApp">
    <hello></hello>
</div>

編寫控制器代碼:rest

<script src="http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js"></script>
    <script>
        var myApp = angular.module("myApp", []);
        myApp.directive("hello", function(){
                return{
                    restrict:'E',
                    template:'<p>hello,你好!!</p>',
                    replace: true
                }
        });
    </script>

這樣網頁運行輸出:code

hello,你好!!blog

相關文章
相關標籤/搜索