Javascript 将按钮列表中的角度按钮设置为选中状态
我试图让我的一个按钮被选中,无论是在初始化得到一个改变,它的css选择和第二次取代它的点击,并保持它为选中。当前单击按钮时,切换到“选定”并返回到“未选定”。此外,我需要将它们保持为一次只选择一个 我的角度模块代码:Javascript 将按钮列表中的角度按钮设置为选中状态,javascript,html,angularjs,Javascript,Html,Angularjs,我试图让我的一个按钮被选中,无论是在初始化得到一个改变,它的css选择和第二次取代它的点击,并保持它为选中。当前单击按钮时,切换到“选定”并返回到“未选定”。此外,我需要将它们保持为一次只选择一个 我的角度模块代码: 'use strict'; (function () { class operationBroadComponent { constructor() { this.buttonsList1 = [ {title: 'title1',
'use strict';
(function () {
class operationBroadComponent {
constructor() {
this.buttonsList1 = [
{title: 'title1', iconDefaultPath: 'icon0 tab enable', iconPressedPath: 'icon0 tab selected'},
{title: 'title2', iconDefaultPath: 'icon1 tab enable', iconPressedPath: 'icon1 tab selected'},
{title: 'title3', iconDefaultPath: 'icon2 tab enable', iconPressedPath: 'icon2 tab selected'},
]
}
}
$onInit() {
}
$onChanges(changedObj) {
}
angular.module('myApp')
.component('operationBroad', {
templateUrl: 'app/windowsComponent/operationBroad/operationBroad.html',
controller: operationBroadComponent,
transclude: true,
bindings: {}
})
.controller('OperationBroadCtrl', function($scope, $http){
var mybtnList = $scope.$parent.$ctrl.buttonsList1;
});
})();
我的html代码:
<div class="operation-broad-container" ng-controller="OperationBroadCtrl">
<div class="col buttons-container">
<operation-button ng-repeat="button in $ctrl.buttonsList1"
title="{{button.title}}"
default-img="{{button.iconDefaultPath}}"
pressed-img="{{button.iconPressedPath}}">>
</operation-button>
</div>
>
谢谢 这段代码的哪一部分没有按预期工作?这并不是说它没有工作,我似乎无法从操作BroadCtrl控制器中将按钮切换到selected(选定)状态如何?这里没有任何代码显示您所描述的内容;这里没有css,甚至似乎也没有点击处理程序。这正是我要问的,创建点击处理程序的方法是什么,除了在加载时设置一个默认的按钮索引0以被按下外,还将指示哪个按钮被按下;您有一个
控制器:
参数指向一个类,这毫无意义,您通过执行$scope.$parent.$ctrl
完全无法使用组件。如果你提出了一个问题清单而不是一个需求清单,那么你就更容易理解你遇到的问题。