通过AngularJs触发引导模式,然后通过$http.post获取数据
我有一个客户名单,每个客户都有更多信息。 我想,当我点击它,然后通过AngularJs控制器显示引导模式,然后通过$http.post请求数据,获得关于该客户的更多信息,并在模式内显示信息。 我怎样才能达到这个目的? 此按钮:通过AngularJs触发引导模式,然后通过$http.post获取数据,angularjs,twitter-bootstrap,bootstrap-modal,Angularjs,Twitter Bootstrap,Bootstrap Modal,我有一个客户名单,每个客户都有更多信息。 我想,当我点击它,然后通过AngularJs控制器显示引导模式,然后通过$http.post请求数据,获得关于该客户的更多信息,并在模式内显示信息。 我怎样才能达到这个目的? 此按钮: <button type='button' class='btn btn-primary btn-sm' data-ng-click='moreinfo(customer.id)' >more info</button> 更多信息 使用ngDi
<button type='button' class='btn btn-primary btn-sm'
data-ng-click='moreinfo(customer.id)' >more info</button>
更多信息
使用ngDialog而不是引导模式
它很容易在angularjs中实现,您也可以为它使用不同的控制器,并且您可以明确地将数据从主页传输到这个对话框。
使用ngDialog而不是引导模式 它很容易在angularjs中实现,您也可以为它使用不同的控制器,并且您可以明确地将数据从主页传输到这个对话框。
我知道您不需要更多的JS插件,但我建议您使用Angularjs的UI引导: 它基本上是一组预定义的指令,可以用来加载引导组件 在你的情况下,事情可以这样结束:
<button type="button" class="btn btn-primary" ng-click = "moreinfo(customer.id)"> More Info </button>
然后创建另一个控制器MoreInfoCtrl:
angular.module('myApp').controller('MoreInfoCtrl',['$http','$scope','id', function($http, $scope, id){
//Do your http call with the variable id (i.e the customer.id )
}]);
你有很多选择。您可以轻松地传递变量、作用域或执行回调过程。
我在一个项目中经常使用它,它真的帮助很大。
我建议你试试。而且它不是很重(从上面的链接):
无论你选择哪种方法,好消息是一个整体的大小
下载量相当小:所有指令的下载量都减少了122K
模板和98K,不带(~31kB,带gzip压缩,带
模板和28K gzip(不带)
我知道你不想要更多的JS插件,但我建议你使用Angularjs的UI引导: 它基本上是一组预定义的指令,可以用来加载引导组件 在你的情况下,事情可以这样结束:
<button type="button" class="btn btn-primary" ng-click = "moreinfo(customer.id)"> More Info </button>
然后创建另一个控制器MoreInfoCtrl:
angular.module('myApp').controller('MoreInfoCtrl',['$http','$scope','id', function($http, $scope, id){
//Do your http call with the variable id (i.e the customer.id )
}]);
你有很多选择。您可以轻松地传递变量、作用域或执行回调过程。
我在一个项目中经常使用它,它真的帮助很大。
我建议你试试。而且它不是很重(从上面的链接):
无论你选择哪种方法,好消息是一个整体的大小
下载量相当小:所有指令的下载量都减少了122K
模板和98K,不带(~31kB,带gzip压缩,带
模板和28K gzip(不带)
我会建议你使用ui引导,但看看其他答案,并考虑到你不想添加更多的JS库/插件 希望这对你有帮助 添加一个名为bootstrapmodel的指令,如下所示
app.directive('bootstrapModal', ['$rootScope', '$http', function ($rootScope, $http) {
"use strict";
return {
restrict: "A",
//add isolated scope if you want
//scope: {
//},
link: function (scope, element) {
scope.$on('showModal', function (event, object) {
//fire your ajax here
$http.get('url').then(function(response){
//process your response alter DOM and show modal
element.modal('toggle');
});
});
}
};
}]);
在控制器中的moreInfo函数中
$scope.moreInfo = function(){
$rootScope.$broadCast('showModal', dataToPassToListener)
}
您应该将指令与要显示为模态的div一起使用。在同一个div中,如果您使用simple bootstrap.js,您将给出role=“dialog”,我建议您使用ui bootstrap,但查看其他答案,并考虑您不想添加更多的js库/插件 希望这对你有帮助 添加一个名为bootstrapmodel的指令,如下所示
app.directive('bootstrapModal', ['$rootScope', '$http', function ($rootScope, $http) {
"use strict";
return {
restrict: "A",
//add isolated scope if you want
//scope: {
//},
link: function (scope, element) {
scope.$on('showModal', function (event, object) {
//fire your ajax here
$http.get('url').then(function(response){
//process your response alter DOM and show modal
element.modal('toggle');
});
});
}
};
}]);
在控制器中的moreInfo函数中
$scope.moreInfo = function(){
$rootScope.$broadCast('showModal', dataToPassToListener)
}
您应该将指令与要显示为模态的div一起使用。在同一个div中,如果使用simple bootstrap.js,您将给出role=“dialog”,您可以首先将每个customer info变量传递给每个其他信息 按钮如下:
<button type='button' class='btn btn-primary btn-sm btnmargin'
data-toggle='modal' data-target='#cInfo' data-ng-click='moreinfo(customer)'
>more info</button>
Html引导模式:
<!-- Modal start -->
<div class='modal fade' id='cinfo' tabindex='-1' role='dialog'
aria-labelledby='myModalLabel' aria-hidden='true'>
<div class='modal-dialog modal-lg' role='document'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal'>
<span aria-hidden='true'>×</span>
<span class='sr-only'>Close</span></button>
<h4 class='modal-title text-danger'
id='myModalLabel'>customer info</h4>
</div>
<div class='modal-body'>
{{customerinfo.firstName}}
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default'
data-dismiss='modal'>close</button>
</div>
</div>
</div>
</div>
<!-- Modal end -->
&时代;
接近
客户信息
{{customerinfo.firstName}
关闭
现在,您可以单击每行按钮“更多信息”并查看模态正文内部的信息。您可以首先将每个客户信息变量传递给每个更多信息 按钮如下:
<button type='button' class='btn btn-primary btn-sm btnmargin'
data-toggle='modal' data-target='#cInfo' data-ng-click='moreinfo(customer)'
>more info</button>
Html引导模式:
<!-- Modal start -->
<div class='modal fade' id='cinfo' tabindex='-1' role='dialog'
aria-labelledby='myModalLabel' aria-hidden='true'>
<div class='modal-dialog modal-lg' role='document'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal'>
<span aria-hidden='true'>×</span>
<span class='sr-only'>Close</span></button>
<h4 class='modal-title text-danger'
id='myModalLabel'>customer info</h4>
</div>
<div class='modal-body'>
{{customerinfo.firstName}}
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default'
data-dismiss='modal'>close</button>
</div>
</div>
</div>
</div>
<!-- Modal end -->
&时代;
接近
客户信息
{{customerinfo.firstName}
关闭
现在,你可以点击每一行按钮了解更多信息,并在模态体内部查看信息。添加一块手表或使用广播并直接收听。你能举个例子告诉我吗?添加一块手表或使用广播并直接收听吗?你能举个例子告诉我吗?我不想使用更多的js插件,因为当js文件很重时,它会影响seo。然后我应该使用bootstrap模式。我不想使用更多的js插件,因为当js文件很重时,它会影响seo。然后我应该使用引导模式。我是否可以编写原始引导模式标记,然后在单击每个客户更多信息时更改模式正文的内容?是的,但您必须广播该事件。我假设您只有一个模态div。如果您计划有多个模态div,那么您必须使用隔离作用域。我是否可以编写原始引导模态标记,然后在单击每个客户的“更多信息”时更改模态体的内容?是的,但您必须广播事件。我假设您只有一个模态div。如果您计划有多个模态div,那么您必须使用隔离作用域。您还可以完美地获取您感兴趣的代码片段,并根据您的需要进行调整。该项目为Github中的每个组件提供了单独的目录。您还可以完美地获取您感兴趣的代码片段,并根据需要进行调整。该项目为Github中的每个组件提供单独的目录。