Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <p>Result:</p>
  <datan-type content="test1"></datan-type>
</body>
</html>
 
var app = angular.module('myApp', []);
app.directive('datanType', function ($compile) {
        var testTemplate1 = '<h1>Test1</h1>';
        var testTemplate2 = '<h1>Test2</h1>';
        var testTemplate3 = '<h1>Test3</h1>';
        var getTemplate = function(contentType){
            var template = '';
            switch(contentType){
                case 'test1':
                    template = testTemplate1;
                    break;
                case 'test2':
                    template = testTemplate2;
                    break;
                case 'test3':
                    template = testTemplate3;
                    break;
            }
            return template;
        }; 
        var linker = function(scope, element, attrs){
          element.html(getTemplate(attrs.content));
          $compile(element.contents())(scope);
          
        };
        return {
            restrict: "E",
            replace: true,
            link: linker,
            scope: {
                content:'='
            }
        };
});
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers