Welcome to JS Bin
Load cached copy from
 
<html ng-app='app'>
    <head>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
    </head>
    <body ng-controller="appCtrl">
     <blue-label>
       我是在 transclude 里的 a: {{ a }}
       <br />
       <input type="text" ng-model="a">
      </blue-label>
      
      我是在 外面 里的 a: {{ a }}
    </body>
</html>
 
var appModule = angular.module('app', []);
// directive
appModule.directive('blueLabel', function() {
    return {
        restrict: 'E',
        template: '<div style="background:skyblue;"><span ng-transclude></span></div>',
        transclude: true
    };
});
// controller
appModule.controller('appCtrl',function($scope) {
    $scope.a = '初始化内容';
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x