Javascript 函数在单击按钮时未调用,但在加载表单时调用
在下面的代码段中,单击按钮可选择Javascript 函数在单击按钮时未调用,但在加载表单时调用,javascript,angularjs,Javascript,Angularjs,在下面的代码段中,单击按钮可选择filepath1和filepath2不启动函数readCSV()。 但是,readCSV()在表单加载时被触发。 我希望该功能也能在点击按钮时触发 如果你能在这里帮助我,我将不胜感激 谢谢 <!DOCTYPE html> <html ng-app="test" ng-controller="homePage"> <head> <meta http-equiv="Content-Type" content="text/ht
filepath1
和filepath2
不启动函数readCSV()
。
但是,readCSV()
在表单加载时被触发。
我希望该功能也能在点击按钮时触发
如果你能在这里帮助我,我将不胜感激
谢谢
<!DOCTYPE html>
<html ng-app="test" ng-controller="homePage">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0" />
<title>TEST</title>
<link rel="stylesheet" href="_css/compiled.css" />
<link rel="stylesheet" href="_css/style-fonts.css" />
<link rel="stylesheet" href="_css/scrollbar/perfect-scrollbar.min.css" />
<script src="_js/libs/angular.min.js"></script>
</head>
<body>
<header class="wrapper headerWrapper mainColorBG">
</header>
<section class="lightBlueBar">
<h2 class="inlineBlock redText"><span class="circularIcon icon-flask"></span> <span class="text">Reports</span></h2>
<div class="searchBar inlineBlock">
<form method="get" ng-submit="readCSV()">
<div ng-controller="submitController">
<label ng-model="filePath" class="fileLabel inlineBlock button grayButton"><span class="icon-cloud-upload"></span><span>Upload</span> <input type="file" ng-model="csvPath"/></label>
<button ng-model="filePath1" ng-click="readCSV()" class="button blueButton"><span class="icon-paper-plane"></span> SUBMIT</button>
<button ng-model="filePath2" ng-click="readCSV()">submit</button>
</div>
</form>
</div>
</section>
</body>
</html>
尝试:
您声明控制器的方式是错误的<控制器中不需要strong>readCSV。并且控制器总是在应用程序加载时启动 要调用函数,请执行以下操作
var test=angular.module("test",[]);
test.controller('submitController',function($scope, $http){
$scope.readCSV=function(){
//Do something
};
});
知道了!谢谢你的解释。我希望我能,但我没有足够的声誉这么做。
var test = angular.module("test", []);
test.controller('submitController', function ($scope, $http) {
$scope.readCSV = function () {
var csv = "hello";//$scope.csvPath;
$scope.filePath1;
alert(csv);
}
});
var test=angular.module("test",[]);
test.controller('submitController',function($scope, $http){
$scope.readCSV=function(){
//Do something
};
});