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。但現在我會嘗試以純粹的角度做它 –