以前有一个<div>,我正在切换的内容ng-click。使用 Angular 1.5 中的组件,我移动了 的内容<div>并创建了一个component. 我现在想加载这个component。ng-click
这可能吗 ?
我还没有找到任何帮助。如果可能的话,帮助将是巨大的。
以前有一个<div>,我正在切换的内容ng-click。使用 Angular 1.5 中的组件,我移动了 的内容<div>并创建了一个component. 我现在想加载这个component。ng-click
这可能吗 ?
我还没有找到任何帮助。如果可能的话,帮助将是巨大的。
它可以显示/隐藏组件(具有您的 div 内容)。我已经创建了一个 plnkr,请参考下面的代码和 plnkr 链接
https://plnkr.co/edit/sZSfslXTDGfvGwiDdBSZ?p=preview
HTML:
<!DOCTYPE html>
<html ng-app="componentApp">
<head>
<script data-require="angularjs@1.5.8" 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"
});