각도 (어제 시작)와 다음을 달성하는 가장 좋은 방법을 구상하려고합니다. 내가 뭘하고 싶은건 컴파일 된 HTML을로드하고 DOM에 주입하는 것이다. 이 질문의 후속 조치는 first time writing an Angular directives and returning a compiled template입니다. 전화하기보다는사용자가 Angular 각도로 이벤트를 클릭 할 때 템플릿 반환
<div my-customer></div>
사용자 상호 작용을 기반으로 동적으로 템플릿을로드하고 싶습니다. 나는이를 반환하는 방법을 알아낼 수 있다면,이 간단한 소리를하지만 약간 불투명 한 각도 문서를 찾을 경우
<div ng-click="loadMyCustomer()">load customer</div><!-- should load here -->
....
arcModule.controller('MainCtrl', function($scope, $http){
$scope.sayHello(){
alert("hello here");
}
$scope.loadMyCustomer=function(){
//alert("hello");
// return the template in the mycustomer directive and place it after the current DOM element from which it is called
}
$scope.customer = {
name: 'Naomi',
address: '1600 Amphitheatre'
};
});
arcModule.directive('myCustomer', function() {
return {
template: 'Name: {{customer.name}}<button ng-click="sayHello()">Click to say hello.</button> Address: {{customer.address}}'
};
});
미안 해요, 난 매우 행복 할 것 : 같은 것을 말한다. 그렇다면 loadMyCustomer 메서드를 통해 지시문에서 템플릿을 어떻게 반환할까요?