2017-01-30 6 views
0

저는 AngularJS를 처음 접했고 코스 (구형의 이전 버전)를 따르는 동안 문제가 발생했습니다. 사용자 지정 지시문을 작성한 후에는보기 측면에서 호출되지 않습니다. 여기 내 HTML 코드입니다 :AngularJS Custom 지시어 문제

<h3>Results Found:</h3> 
<div class="list-group"> 
    <search-result></search-result> 
</div> 

그리고 여기 JS 코드입니다 :

myApp.directive('searchResult', function() { 
    return { 
     template: '<a href="#" class="list-group-item active"><h4 class="list-group-item-heading">Doe, John</h4><p class="list-group-item-text">555 Some St, New York, NY 101010</p></a>' 
    } 
}); 

참고 : 나는 현재 버전 AngularJS와의 1.6.1와 함께 일하고 있습니다. 누구든지 나를 도울 수 있습니까? 는

+0

당신의 HTML에 NG-응용 프로그램이 있나요 (사전에 모두 감사합니다)? –

+0

Nicolas를 지적 해 주셔서 대단히 감사합니다. 네, 에 ng-app 권한이 있습니다. 그러나 어떤 이유로 텍스트 편집기를 다시 시작하고 이제는 정상적으로 실행됩니다 ... 이해가 가지 않습니다. 그러나 당신의 도움에 다시 한번 감사드립니다 Nicolas –

답변

0

DEMO

var myApp = angular.module('DirectiveApp', []); 
 

 
myApp.controller("mainController", ["$scope", "$http", 
 
    function($scope, $http) { 
 
     
 
    } 
 
]); 
 
myApp.directive('searchResult', function() { 
 
    return { 
 
     template: '<a href="#" class="list-group-item active"><h4 class="list-group-item-heading">Doe, John</h4><p class="list-group-item-text">555 Some St, New York, NY 101010</p></a>' 
 
    } 
 
});
<!DOCTYPE html> 
 
<html ng-app="DirectiveApp"> 
 
<head> 
 
    <title>List</title> 
 
    <link href="skeleton.css" rel="stylesheet" /> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script> 
 
    </head> 
 
<div ng-controller="mainController"> 
 
    <div class="container"> 
 
    <search-result></search-result> 
 
    </div> 
 
</div> 
 
</body> 
 

 
</html>

+0

왜 downvote guys – Sajeetharan

+0

당신의 도움에 감사 Sajeetharan. 나는 텍스트 편집기를 다시 시작했는데 이유가 무엇이든 모두 결국 괜찮 았어. 하지만 당신의 코드를보고 내가 모르는 것들을 발견 했으니까요. 당신의 도움을 주셔서 대단히 감사합니다!! –

관련 문제