В приведенном ниже фрагменте кода кнопка нажимает для filepath1
и filepath2
не readCSV()
функцию 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>
var test=angular.module("test",[]);
test.controller('submitController',function readCSV($scope, $http){
var csv = "hello";//$scope.csvPath;
$scope.filePath1;
alert(csv);
});
То, как вы объявили контроллер, неверно. 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);
}
});