gpt4 book ai didi

javascript - AngularJS 指令中的设置模型为空

转载 作者:行者123 更新时间:2023-12-03 10:50:05 25 4
gpt4 key购买 nike

我想在更改选中或未选中的复选框时将指令中的 modelvalue 设置为 Null。

HTML

<input type="checkbox" ng-model="isCheck"  />
<select ng-model="empNmae" ng-setempty="isCheck"
ng-options="em.Value as em.Name for em in emp">
<option value="">Select
</select>
{{empNmae}}

JS

// Code goes here
var app=angular.module('myApp',[]);
app.controller("mycntrl", function ($scope) {
$scope.emp=[{
"Name":"Amit",
"Value":101
},{
"Name":"Amit2",
"Value":103
},{
"Name":"Amit3",
"Value":102
}];
$scope.empNmae=102;
$scope.isCheck=true;
});

app.directive('ngSetempty', function () {
return {
restrict: 'A',
require: 'ngModel',

link: function (scope,element, attrs, ctrl) {
scope.$watch(attrs.ngSetempty, function () {
var getChekc=this.last;
if(getChekc){
// set Model is NULL
}
});

}
};
});

如果选中复选框,那么我想将选择框的模型设置为空。<强> Plunker

最佳答案

您是否尝试过简单的:

delete $scope.empNmae

关于javascript - AngularJS 指令中的设置模型为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28451399/

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