gpt4 book ai didi

javascript - AngularJS:自动选择单选按钮

转载 作者:行者123 更新时间:2023-12-02 14:25:50 24 4
gpt4 key购买 nike

我有两个单选按钮,我希望自动选择第一个

<input type="radio" name="playlist" ng-value="myCtrl.cleanPlaylist" ng-model="myCtrl.playlistSelected"> Clean

<input type="radio" name="playlist" ng-value="myCtrl.explicitPlaylist" ng-model="myCtrl.playlistSelected" ng-disabled="myCtrl.

我在 Controller 中选择了第一个,但由于某种原因它不起作用...

var myModule = angular.module("MyApp", []).controller('MyController', function(){

this.explicitDisabled = false;

this.playlistSelected = this.cleanPlaylist;

})

最佳答案

您必须为单选按钮设置一个值,ng-value是一个 Angular 表达式,当选择单选按钮时,ng-model将被设置为,根据 docs .

然后,要使其正常工作,您可以执行以下操作:

(function() {
"use strict";
angular.module('app', [])
.controller('mainCtrl', function() {
var vm = this;

vm.playlistSelected = 'clean';
});
})();
<!DOCTYPE html>
<html ng-app="app">

<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.min.js"></script>
</head>

<body ng-controller="mainCtrl as main">
<input type="radio" name="playlist" value="clean" ng-model="main.playlistSelected"> Clean
<input type="radio" name="playlist" value="complete" ng-model="main.playlistSelected"> Complete
</body>

</html>

关于javascript - AngularJS:自动选择单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38256447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com