0

이전에 <div>이 있었는데 그 내용은 ng-click입니다. Angular 1.5의 구성 요소를 사용하여 <div>의 내용을 이동하고 component을 만들었습니다. 이 componentng-click에로드하고 싶습니다.ng-click에서 구성 요소를 호출 할 수 있습니까?

이것이 가능합니까?

아직 도움을 찾지 못했습니다. 가능하다면 도움이 될 것입니다.

+2

하면, 좀 더 확장시겠습니까 나는 plnkr, 아래의 코드와 plnkr 링크

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

HTML을 참조를 만들었습니다? – sergio0983

답변

1

구성 요소를 표시하거나 숨길 수 있습니다 (div 콘텐츠 보유).

<!DOCTYPE html> 
<html ng-app="componentApp"> 

    <head> 
    <script data-require="[email protected]" data-semver="1.5.8" src="https://opensource.keycdn.com/angularjs/1.5.8/angular.min.js"></script> 
    <link rel="stylesheet" href="style.css" /> 
    <script src="script.js"></script> 
    </head> 

    <body ng-controller="componentController"> 
    <button ng-click="showComponent()" id="changeText">Show Component</button> 
    <div-content ng-if="isShowContent"></div-content> 
    </body> 

</html> 

JS :

angular.module("componentApp", []) 
     .controller("componentController", function($scope) { 
     $scope.isShowContent = false; 
     $scope.showComponent = function() { 
      $scope.isShowContent = !$scope.isShowContent; 
      document.getElementById("changeText").innerHTML = $scope.isShowContent ? "Hide Component" : "Show Component"; 
     }; 
     }) 
     .component("divContent", { 
     template: "This is the content of my div" 
     });