使用AngularJS单击按钮时如何清除输入字段?

时间:2020-06-19 22:44:01

标签: angularjs

在JavaScript中是这样的:

df1 = pd.read_csv('PATH',
                           

parse_dates=True, usecols=[0,7,10,13,28], 
                           infer_datetime_format=True, index_col='DateTime')

# Resample data to take minute averages

df1.dropna(inplace=True) # Drops missing values

df1=(df1.resample('Min').mean())

df1.to_csv('df1', index=False, encoding='utf-8-sig')

df1_DateTimes = pd.to_datetime(df1.index.values)

df1_DateTimes = df1_DateTimes.to_frame()

df1_DateTimes.to_csv('df1_DateTimes', index=False, encoding='utf-8-sig'`

如何与AngularJS一起使用?

2 个答案:

答案 0 :(得分:0)

您可以使用ng-model指令解决此问题,这里有一个示例,说明如何在代码中实现它

index.html

<div ng-controller="MainController">
  <p>Clear the input field when you click on the button:</p>
  <button ng-click="clearInput()">Clear input field</button>

  <input type="text" id="myInput" ng-model="input">
</div>

app.js

var myApp = angular.module('myApp',[]);

myApp.controller('MainController', ['$scope', function($scope) {
  $scope.input = '';

  $scope.clearInput = function() {
     $scope.input = '';
  }
}]);

有关更多示例,请参见angularjs文档。 https://docs.angularjs.org/guide/controller

答案 1 :(得分:0)

我成功实现了dom javascript,并内置了onclick事件

<input type="text" id="hdd_data_2" value="3 TB">
<button type="button" onclick="document.getElementById('hdd_data_2').value ''">Clear</button>