[英]Scope updated value into a variable
我有这个:
$scope.data = {
'a' : 0,
'b' : 0,
'c' : 0
}
...以及每个值的值:
<input toggle ng-model="data.a" ng-true-value="10" ng-false-value="0" />
这是一个angularjs v1离子报价计算器的示例,每个字段都有一个值,我用{{data.a}} {{..}}
显示正确的值,最后一个字段是所有{{data.a + data.b + data.c ....}}
我需要将所有字段的真实值传递给javascript变量,才能将范围数据发送到电子邮件:
angular.module('app.mail', []).controller("MailgunController", function($scope, $http) {
var mailgunUrl = "mydomain.com";
var mailgunApiKey = window.btoa("api:key-XXXXXXXXXX");
var recipient = "info@mydomain.com";
var subject = "Quote";
var message = "Results: " + $scope.data.a;
$scope.send = function() {
$http(
{
"method": "POST",
"url": "https://api.mailgun.net/v3/" + mailgunUrl + "/messages",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic " + mailgunApiKey
},
data: "from=" + "info@example.com" + "&to=" + recipient + "&subject=" + subject + "&html=" + message
}
).then(function(success) {
console.log("SUCCESS " + JSON.stringify(success));
}, function(error) {
console.log("ERROR " + JSON.stringify(error));
});
};
});
问题是我收到的电子邮件的默认值为0:
$scope.data.a; // 0
我如何才能将真正的范围数据值转换为var消息?
谢谢
如果在返回结果传递结果到new {}对象时在服务器端使用Web api控制器。 例如:
[HttpPost]
public HttpResponseMessage Insert(LookupViewModel model)
{
try
{
EducationLookup result = AutoMapperGenericsHelper<LookupViewModel, EducationLookup>.ConvertToDBEntity(model);
this.Uow.EducationLookups.Add(result);
Uow.Commit(User.Id);
//Look here
return Request.CreateResponse(HttpStatusCode.OK, new{Result= result});
}
catch (DbEntityValidationException e)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, CustomExceptionHandler.HandleDbEntityValidationException(e));
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.HResult.HandleCustomeErrorMessage(ex.Message));
}
}
在客户端的成功函数上获取json格式。
$scope.send = function() {
$http(
{
"method": "POST",
"url": "https://api.mailgun.net/v3/" + mailgunUrl + "/messages",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic " + mailgunApiKey
},
data: "from=" + "info@example.com" + "&to=" + recipient + "&subject=" + subject + "&html=" + message
}
).then(function(respose) {
//Get server response in block!
$scope.data=respose;
console.log("Send e-mail was successful");
}, function(error) {
console.log(error);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.