Here is my code currently:
<!-- main.html -->
<div ng-controller="MainController">
<button type="button" ng-click="toggleImgView()">Show Images</button>
<div ng-show="showImg">
<ng-include src="'myTemplate.html'"></ng-include>
</div>
</div>
<!-- myTemplate.html -->
<img ng-repeat="src in images" ng-src="{{ src }}/>
/* part of MainController */
$scope.images = [...];
$scope.showImg = false;
$scope.toggleImgView = function () {
$scope.showImg = !$scope.showImg;
};
When main.html
is loaded, myTemplate.html
is default to be hidden because of $scope.showImg = false;
, then I can toggle to show it by clicking the Show Images
button.
Although myTemplate.html
is hidden, it is still loaded to the DOM. It contains a lot of images, which may result in heavy network traffic. Therefore, I don't want load it until the user click the Show Images
button to toggle the template.