angularjs+bootstrap+ngDialog实现模式对话框

首先引入需要的ngdialog的js和css文件。
可通过CDN引入


  
  
var userControllers = angular.module('userControllers',['ngDialog']); userControllers.controller('userController',['$scope','$http','ngDialog',function($scope,$http, ngDialog){ $scope.name = 'user'; $scope.user = ""; $scope.address = ""; //获取用户信息 $http.get('http://localhost:3000/users').success(function(data) { $scope.user = data; console.log($scope.user); }); //点击详细地址按钮时,跳出模式对话框 $scope.clickToAddress = function (address) { $scope.address = address; ngDialog.open({ template: 'views/test.html',//模式对话框内容为test.html className: 'ngdialog-theme-plain', scope:$scope //将scope传给test.html,以便显示地址详细信息 }); }; }])

test.html(读取scope中的address并显示,表格样式采用bootstrap )

<table class="table">  
    <thead>  
    <tr>  
        <th>  
            收件人姓名  
        </th>  
        <td>  
            {{address.name}}  
        </td>  
    </tr>  
    <tr>  
        <th>  
            收件地址  
        </th>  
        <td>  
            {{address.content}}  
        </td>  
        </tr>  
    <tr>  
        <th>  
            手机号  
        </th>  
        <td>  
            {{address.phone}}  
        </td>  
    </tr>  
    </thead>  
  
</table>  

user.html (显示用户的信息,当地址不为空时,显示详细地址按钮,并点击按钮时,调用controller中的clickToAddress函数)

<div>  
    <div class="panel panel-warning">  
        <div class="panel-heading">  
            用户管理  
        </div>  
    <div class="row">  
        <div class="col-lg-8"></div>  
        <div class="col-lg-4">  
            <div class="input-group">  
                <input type="text" class="form-control" placeholder="Search for..." ng-model='search'>  
      <span class="input-group-btn">  
        <button class="btn btn-default" type="button">Go!</button>  
      </span>  
            </div>  
        </div>  
    </div>  
    <table class="table">  
        <thead>  
        <th>姓名</th>  
        <th>余额 <span class="glyphicon glyphicon-flash" aria-hidden="true"> </span></th>  
        <th>头像</th>  
        <th>默认地址</th>  
        <th>操作</th>  
        </thead>  
        <tbody>  
        <tr ng-repeat="user in user | filter : search" >  
            <td>{{user.userName}}</td>  
            <td>{{user.residualPayment}}</td>  
            <td ng-if="user.url != 'undefined' ">{{user.url}}</td>  
            <td ng-if="user.url == 'undefined' ">系统默认头像</td>  
            <td ng-if="user.address.length == 0 ">暂无默认地址</td>  
            <td ng-if="user.address.length != 0"ng-repeat="address in user.address " ng-click="clickToAddress(address)">  
                <button type="button" class="btn btn-info navbar-btn">详细地址</button>  
            </td>  
            <td>  
                <button type="button" class="btn btn-warning navbar-btn" ng-click="remove(user._id)">删除</button>  
            </td>  
        </tr>  
        </tbody>  
    </table>  
        </div>  
</div>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值