【问题标题】:Angularjs | ng-repeat set true or false when selectedAngularjs | ng-repeat 选择时设置 true 或 false
【发布时间】:2018-11-02 00:57:11
【问题描述】:

当我在 angularjs 中选择了我的某些数据时,我如何设置 true 或 false?

例如我有数据

$scope.obj = {
   'id': 1,
   'id': 2,
   'id': 3
}

<div ng-repeat="myData in ctrl.obj">
   <input type="text" class="form-control" placeholder="Notes" ng-model="ctrl.myData ">
</div>

当我输入数据并且等于 id = 1 时,我需要一些帮助,它会将我的值设置为 ID 1,否则它将设置为空,但是当我返回上次选择的输入框时,它仍然会显示我之前输入的输入框的值。感谢协助解决我的逻辑错误:)

【问题讨论】:

  • 不应该显示所有 3 个输入框。只有当输入框被选中时才会改变值。
  • 用户 ng-model="ctrl.myData[]" 这样的
  • @ChiruAdi 你可以为此编写示例代码吗?

标签: angularjs


【解决方案1】:

查看以下可能对您有所帮助的代码:

var abcAPP = angular.module("abcApp",[]);
abcAPP.controller("abcCtrl",function($scope){
	$scope.obj = [{ 'id': 1}, {'id': 2}, {'id': 3 }]
    $scope.myData = ["1","2","3"];
});
<!DOCTYPE html>
<html ng-app="abcApp">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-controller="abcCtrl">
 
<pre ng-bind="myData|json"></pre>
<div ng-repeat="myData1 in obj">
   <input id="{{$index}}" type="text" class="form-control" placeholder="Notes" ng-model="myData[$index]">
</div>
</div>

</body>
</html>

【讨论】:

  • 谢谢chiru,我知道我真正想要什么了:)
猜你喜欢
  • 2014-02-16
  • 1970-01-01
  • 2018-08-27
  • 2016-08-20
  • 1970-01-01
  • 2016-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多