如果我点击另一个div angularjs,改变div风格

时间:2016-06-27 11:55:24

标签: angularjs

当我点击另一个div时,我陷入了改变div风格的困境。我只想更改listAnswer类文本修饰在我点击ng-repeat div1之一时变为下划线。我希望有人可以帮助我:(谢谢

<style>
    .object_screen {
       width: 800px;
       height: 500px;
    }

    .div1 {
       width: 200px;
       height: 200px;
       float: left;
       margin-left: 10px;
    }
</style>

<div class="object_screen">
    <div class="div1" ng-repeat="object in objectList" ng-click="checking(object.name);" ng-style="{'background-image':'url(./img/level/{{ object.image }})}"></div>
</div>
<div class="listAnswer">
    <li ng-repeat="object in objectList">{{ object.name }}</li>
</div>

这是我的角色剧本

var App = angular.module('App', ['ngRoute']);
    App.controller('playController', ['$scope', '$http', function($scope, $http) {
        $scope.objectList = [];
        $scope.objectList.push({name:'tony', image:'image1.png'});
        $scope.objectList.push({name:'Jay', image:'image2.png'});
        $scope.objectList.push({name:'Michael', image:'image3.png'});

        $scope.checking= function(nameObject){
            // change text-decoration to underline for class listAnswer
        }
    }]);

1 个答案:

答案 0 :(得分:0)

您可以在范围中声明一个变量,使其最初具有布尔值false,并在$ scope.checking中将其更改为true,并在后续行中使用ng-class div class =“listAnswer”ng-class =“{'your text decoration css class':在$ scope.checking中设置监视变量}”当变量设置为true时,将应用您的文本修饰类