我目前正在为我的投资组合开发一个MEAN堆栈博客。我的目标是能够在我的Mongoose数据库中存储HTML文件或.docx文件,以便稍后回忆起各个博客文章。作为第一步,我创建了这个表单:
var oApp = angular.module("myApp", []);
oApp.controller("certificationsCtrl", function ($scope, $http)
{
$scope.Exams = {};
$scope.GetPassFail = function (passFail)
{
return passFail ? "Pass" : "Fail";
};
$scope.ShowExams = function (certificationID)
{
var url = "http://localhost:49861/api/Exams?id=" + certificationID + "&extra=0";
$http({
method: "GET",
url: url
}).then(function mySuccess(response)
{
$scope.Exams = response.data;
}, function myError(response)
{
alert("error response.statusText = " + response.statusText);
});
}
});
<tr ng-repeat="x in Exams">
<td style="border: 1px solid black;">{{ x.ExamNumber}}</td>
<td style="border: 1px solid black;">{{ x.ExamShortName }}</td>
<td style="border: 1px solid black;">{{ x.PassFail | GetPassFail }}</td>
MM-dd" }}</td>
</tr>
在Angular控制器中,我有这个代码监听该表单:
<form>
File: <input type = 'file' ng-model = "new_post.file">
<input type = 'date' ng-model = "new_post.date">
<input type = "submit" value = "Submit" ng-click = "save_post(new_post)">
</form>
当我输入要存储并提交表单的HTML文档时,$scope.save_post = function(new_post){
console.log(new_post);
if(new_post.file){
console.log("yo");
}
}
会显示console.log
信息。但是,new_post.date
未显示在日志中,“yo”不会打印。当我尝试记录new_post.file
时,它显示为new_post.file
。如何以控制器可以识别的形式存储文件,以便将其传递到我的工厂并最终传递到我的数据库?