当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - Custom directive not rendering

问题描述:

In this directive I'm attempting to display the result of multiple get requests :

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

src :

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'

];

}

But nothing is being rendered. Am I defining the directive correctly ?

网友答案:

Use ng-include in mytemplate.html

https://plnkr.co/edit/gPoRn89anqn7uLRMYVSG?p=preview

分享给朋友:
您可能感兴趣的文章:
随机阅读: