2016-01-23 4 views
0

В этой директиве я пытаюсь отобразить результат множественных запросов GET:Пользовательские директивы не оказывающего

plnkr: https://plnkr.co/edit/BjETLN7rvQ1hNRIm51zG?p=preview ЦСИ:

http-hello1.html : 
{ "content" : "divContent" , "id" : "r1" } 
http-hello2.html : 
2. http-hello2.html 
http-hello3.html : 
3. http-hello3.html 

index.html : 

<!doctype html> 
<html ng-app> 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> 
    <script src="script.js"></script> 
    </head> 
    <body> 

    <div ng-controller="FetchCtrl"> 

    <source-viewer ng-repeat="sourceUrl in sourceUrls" url="sourceUrl"></source-viewer> 
</div> 


    </body> 
</html> 


mytemplate.html : 

<h1>{{url}}</h1> 
<div> 
    <p>{{model.address}}</p> 
</div> 

script.js : 

// Example of how to call AngularJS $http service and 
var myapp = angular.module('app', []).controller('FetchCtrl', FetchCtrl) 

myapp.directive('sourceViewer', function ($http) { 
      return { 
       restrict: 'E', 
       templateUrl: 'mytemplate.html', 
       scope: { 
        url: '=' 
       }, 
       link: function (scope, elem, attrs, ctrl) { 
        $http.get(scope.url).success(function (data) { 
         $scope.model = data.data; 
        }); 
       } 
      }; 
     }); 

function FetchCtrl($scope, $http, $q , $parse) { 


$scope.sourceUrls = [ 
       'http-hello1.html', 
       'http-hello2.html', 
       'http-hello3.html' 
      ]; 



} 

Но ничего визуализируется. Я правильно определяю эту директиву?

+1

В вашем HTML тег, у вас есть директива нг-приложение, но не уточняя, какой модуль для загрузки. Попробуйте –

+0

@ShaunScovil работает, спасибо https://plnkr.co/edit/BjETLN7rvQ1hNRIm51zG?p=preview –

ответ

Смежные вопросы