我在angularjs中创建了讨论论坛应用程序。一旦用户点击帖子上的回复按钮,我想显示在单独的html文件中的编辑器。如何在单击特定帖子下的ng-click时包含该模板。
答案 0 :(得分:1)
ng-include
与ng-if
的组合怎么样?
如果要根据特定条件注入模板,可以这样做:
<div ng-include="'template.html'" ng-if="yourCondition"> </div>
其中template.html
是您的文件名,yourCondition
应该是布尔表达式。
答案 1 :(得分:0)
如上所述,我们可以结合使用ng-if和ng-include来实现所需的功能:
<html ng-app="includeApp">
<head>
<script type ="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.js"></script>
<script src="AppController.js"></script>
</head>
<body ng-controller="AppCtrl">
<button ng-click="injectReply()">Include Reply</button>
<div ng-include="'reply.html'" ng-if="isReplyIncluded"></div>
</body>
</html>
现在包含AppController.js的代码:
angular.module('includeApp',[])
.controller('AppCtrl',['$scope',function($scope){
$scope.isReplyIncluded=false;
$scope.injectReply= function (){
//add reply.html by making this variable true
$scope.isReplyIncluded=true;
}
}]);
Reply.html
<div>
You can add your editor html content here
</div>