angular.js - Click event in Angularjs passes parameters to change the style of the class.
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-15 17:03:12
0
2
932

The picture you want to achieve is as follows:

Now I have implemented the basic shape and function, but when I click on an icon and change the icon next to "Adapted Devices", this function does not produce the expected results.
Please tell me which part I wrote wrong?

1. Here are the icons that will be replaced by clicking the icons in different drop-down boxes next to "Adapted Devices".
(This is the function I want to achieve.)

<i 
 ng-class="{' ico-screen-pc':pc,
            ' ico-screen-projector':projector,
            ' ico-screen-tv':tv}">
</i>

2. This part is in the drop-down box. You can click on different icons

<ul  ng-show="show_apparatus">
      <li  ng-click="displayModeData.choose_display('pc')">   
           <i  title="PC显示屏" class="ico-screen-pc"></i>
      </li>
      <li  ng-click="displayModeData.choose_display('projector')">   
           <i  title="投影仪" class="ico-screen-projector"></i>
      </li>
      <li ng-click="displayModeData.choose_display('tv')">
           <i  title="TV显示屏" class="ico-screen-tv"></i>
      </li>
</ul>

3. This part is the function code of js

        $scope.pc = true;
        
        $scope.displayModeData = {
            pc: true,
            choose_display : function( displayMode ){
                $scope.pc = ( displayMode === 'pc' );
                $scope.projector = ( displayMode === 'projector' );
                $scope.tv = ( displayMode === 'tv' );
            }
        };

Please tell me which part of my writing is wrong?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
PHPzhong

Come on, change it according to mine:

$scope.displayModeData = {
    pc: true,
    choose_display : function( displayMode ){
        $scope.displayMode = displayMode;
    }
};
<i 
 ng-class="{' ico-screen-pc':displayMode === 'pc',
            ' ico-screen-projector': displayMode === 'projector',
            ' ico-screen-tv': displayMode === 'tv'}">
</i>
某草草
<i class="{{selectedClass}}"> </i>
<ul ng-show="show_apparatus">
    <li ng-click="$parent.selectedClass = icon.className" ng-repeat="icon in icons">
        <i title="{{icon.title}}" class="{{icon.className}}"></i>asdadasd
    </li>
</ul>
$scope.icons = [
    {title: 'PC显示屏', className: 'ico-screen-pc'},
    {title: '投影仪', className: 'ico-screen-projector'},
    {title: 'TV显示屏', className: 'ico-screen-tv'}
];
$scope.selectedClass = $scope.icons[0].className;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template