angularjs指令-控制器

1.指令-控制器.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>angularjs指令</title>
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
    <script src="jquery-2.1.3.min.js"></script>
    <script src="bootstrap.min.js"></script>
    <script src="angular.min.js"></script>
</head>
<!-- directive调用参数时,需要在scope里面指定,比如template要调用controller里面的name,
    则需要先在渲染的span里面定义一个qw-color标签,directive的scope里面定义color取qw-color的name
    调用函数时用的是'&',调用参数是用的是'='-->
<body ng-app="kongwc">
    <qing-wei></qing-wei>
    <!-- 多个table可以在此添加多条-->
    <qing-wei></qing-wei>
</body>
<script>
    var app = angular.module('kongwc',[]);
    app.directive('qingWei',function () {
        return {
            restrict : 'E',
            replace : true,
            templateUrl : 'table.html',
           controller : (function ($scope) {
               $scope.datas = [
                   { id: "1", name : "小白牛", phone : "13465352119" },
                   { id: "2", name : "迷迭香", phone : "1565354662" },
                   { id: "3", name : "龙之谷", phone : "13765354891" }
               ];
           })
        }
    });
</script>
</html>

2.table.html

<table class="table table-striped">
    <tr>
        <th>序号</th>
        <th>姓名</th>
        <th>电话</th>
    </tr>
    <tr ng-repeat="data in datas">
        <td>{{data.id}}</td>
        <td>{{data.name}}</td>
        <td>{{data.phone}}</td>
    </tr>
</table>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

裂魂人1214

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值