PS:有點(diǎn)繞 琢磨一下。虹蒋。校坑。拣技。。耍目。
<!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">點(diǎn)贊標(biāo)簽</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:'標(biāo)題一號(hào)',Time:'2016-07-29',LikeAmount:0},
{Username:'李四',Title:'標(biāo)題二號(hào)',Time:'2016-07-29',LikeAmount:0},
{Username:'二麻',Title:'標(biāo)題一號(hào)',Time:'2016-07-29',LikeAmount:0},
];
});
app.directive ("like",function(){
var direction = {};
direction.restrict = 'AE';
direction.template = '<button ng-click="like()">點(diǎn)擊</button>';
direction.scope = {
content:"="
};
direction.link = function ($scope,element){
$scope.like = function (){
$scope.content.LikeAmount = $scope.content.LikeAmount + 1;
};
};
return direction;
});
</script>
</html>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者