[AngularJS] Transclude -- using what existing in DOM to replace the template elements in directive

var app = angular.module("phoneApp", []);

app.controller("AppCtrl", function($scope) {

});

app.directive("panel", function() {
    return {
        restrict: "E",
        transclude: true,
        template: '<div class="panel" ng-transclude>This is a panel component</div>'
    }
})
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Angular Scope &</title>
    <link href="foundation.min.css" rel="stylesheet"/>
    <script src="angular.min.js"></script>
    <script src="app.js"></script>
</head>
<body >
<div ng-app="phoneApp">
    <div ng-controller="AppCtrl">
        <panel>
            <div class="button">Click me!</div>
        </panel>
    </div>
</div>
</body>
</html>

posted @ 2014-08-24 05:05  Zhentiw  阅读(257)  评论(0编辑  收藏  举报