angularjs - 如何以模态方式打开整个html页面?
问题描述
我对 angularjs 很陌生,目前正在研究平均堆栈。我正在使用此代码打开一个 html 页面,然后获取点击用户的 id。
<a href="/edit/{{ person._id }}">
<button type="button" ng-show="management.editAccess" class="btn btn-primary">Edit</button>
</a>
但我想将我的 html 作为模态打开,我在这里尝试了这个方法http://plnkr.co/edit/Y7jDj2hORWmJ95c96qoG?p=preview但它没有显示 html,请帮助我如何打开我的整个 html作为模态。
解决方案
您需要$http.get
在 html 中的模板,然后使用$sce
渲染它。
<button data-toggle="modal" data-target="#theModal" ng-click="get()">get</button>
<div id="theModal" class="modal fade text-center">
<div class="modal-dialog">
<div class="modal-content">
<div ng-bind-html="trustedHtml"></div>
</div>
</div>
</div>
JS:
$scope.get = function() {
$http({
method: 'GET',
url: 'Lab6.html',
})
.then(function successCallback(data){
$scope.data = data.data;
console.log($scope.data);
$scope.trustedHtml = $sce.trustAsHtml($scope.data);
},
function errorCallback(response){
console.log(response);
console.log('error');
});
}
这是工作 plunker:http ://plnkr.co/edit/SdCAep1dDH8UcpprwDH6?p=preview
另外我认为您可能应该使用 Angular UI Bootstrap 来创建模态对话框http://angular-ui.github.io/bootstrap/
以下是如何使用 Angular UI Bootrstrap 打开模式的精简版:
$scope.open = function (vehicle) {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
resolve: {
items: function () {
return $scope.items;
}
}
});
};
推荐阅读
- node.js - 使用 React 和 Express 在没有谷歌分析的情况下收集页面视图数据
- php - 如何使用单例模式在 php 中正确编写数据库类?
- keycloak - 如何在 keycloak 中查看文档
- python - 找到解决方案/返回后如何停止递归
- java - 在已经声明并赋值时无法解析为变量?
- vue.js - 在 vuetify 的 v-text-field 中使用 v-mask 时未设置数据
- batch-file - 你能克隆一个 git repo 并将所有包更新到最新版本吗
- python - 请求有关网络抓取问题的帮助
- html - 如何在 html 文件中加载 html 链接
- typescript - 我如何将传递给有效负载创建者的参数类型与来自 RTK 中有效负载创建者的返回类型混合在一起?