var myApp = angular.module("myApp", []);
myApp.controller("votesController", ['$scope', function($scope, $timeout) {
$scope.comments = [
];
$scope.newComment = {
likes: 0
};
$scope.createComment = function() {
if ($scope.newComment.comment != "") {
$scope.comments.push({
comment: $scope.newComment.comment,
likes: $scope.newComment.likes
});
}
};
$scope.incrementLikes = function(comment) {
comment.likes++;
};
$scope.decrementLikes = function(comment) {
comment.likes--;
};
}]);
$('a.vote_comment').on('click',function(){
\t $(this).css('color','red'); \t \t \t \t \t \t
\t });
$('a.vote_dis_like_comm').on('click',function(){
\t $(this).css('color','green');
\t });
a
{
cursor:pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="container" ng-app="myApp">
<div ng-controller="votesController">
<div ng-repeat="comment in comments">
<div class="comment_box_all">
<div class="comment_user">
<div class="comment_note">
<a ng-click="incrementLikes(comment, $index)" class="vote_comment">Like</a>
<span class="num_vote_comm_11"> | {{comment.likes}} | </span>
<a ng-click="decrementLikes(comment, $index)" class="vote_dis_like_comm">Unlike</a>
</div>
<div class="content_text_user_ans"><span>{{comment.comment}}</span></div>
</div>
</div>
</div>
<div class="area_comm_tex">
<textarea class="text_area" ng-model="newComment.comment" placeholder="Add comment"></textarea>
<button class="op_comm_now" ng-click="createComment()">Add text</button>
</div>
</div>
</div>
这是非常简单的评论框,但我有一个问题。你能向我解释为什么用jQuery改变CSS样式不工作?我想要改变颜色文字/不像onclick,但这不起作用。
你试图把它在的document.ready – chiliNUT
为什么jQuery和不'ngClass' +'ngClick'?这是Angular,不要用jQuery代码污染它 –
Angular对我来说是新的,我正在改变纯js和jquery中的代码,我认为它可以结合使用jquery和angular。但现在我会尝试以纯粹的角度做它 –