菜鸡学AngularJS 12 模块化 网上的一个示例

PS:有点绕 琢磨一下。。。。。。
<!doctype html>
<html ng-app = "myapp" ng-controller = "Test">
<head>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body >
<div>
    <ul>
        <li ng-repeat="List in Userlist">
            <label>{{List.Username}}</label><br />
            <label>{{List.Title}}</label><span>{{List.LikeAmount}}</span><like content = "List">点赞标签</like><br />
            <label>{{List.Time}}</label>
        </li>
    </ul>
</div>

</body>
<script>
var app = angular.module('myapp', []);
app.controller("Test", function($scope){
    $scope.Userlist = [
        {Username:'张三',Title:'标题一号',Time:'2016-07-29',LikeAmount:0},
        {Username:'李四',Title:'标题二号',Time:'2016-07-29',LikeAmount:0},
        {Username:'二麻',Title:'标题一号',Time:'2016-07-29',LikeAmount:0},
    ];
});

app.directive ("like",function(){
    var direction = {};
    direction.restrict = 'AE';
    direction.template = '<button ng-click="like()">点击</button>';

    direction.scope = {
        content:"="
    };

    direction.link = function ($scope,element){
        $scope.like = function (){
            $scope.content.LikeAmount = $scope.content.LikeAmount + 1;
        };
    };

    return direction;

});


</script>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容