我在一个名为accountManager的服务中有一个函数,该函数返回如下所示的promise:
该承诺上的.then()会触发并打印出预期的响应。
signIn(email:String,password:String):Promise<any>{
return this.http.post('http://localhost:3000/api/signin',JSON.stringify({
"email": email,
"password": password
}),{headers: this.headers})
.toPromise()
.then(res => {
//**This is defined**
console.log(res);
})
}
Run Code Online (Sandbox Code Playgroud)
当我在另一个使用此signIn方法的类中时,就会出现问题。承诺内的响应现在为空。当我从函数本身省略承诺时,返回的承诺的.then()具有响应值。
if (this.loginForm.valid === true){
this.accountManager.signIn(this.email,this.password)
.then(response =>{
//**This .then has an undefined response when added on to the promise returned from the signIn function.**
let body = JSON.parse(response._body)
if (body.payload.success === true){
this.router.navigate(['/']);
}else{
this.signInError = true;
}
})
.catch(error=>{
this.signInError = true;
})
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么在返回诺言但诺言给定的诺言中没有值的情况下,诺言.then()为何包含一个值?我很高兴澄清是否有任何令人困惑的地方。谢谢 :)
我和我的同事一起创建了一个 Angular 5 应用程序。我为所有界面创建了一个文件夹,并按功能对它们进行分组。但是,我没有在它们上包含任何导出符号,并且在使用它们时,我永远不需要导入它们......它们只是存在并且不会产生任何编译错误。我喜欢这种方式,因为它使代码更干净,但我只是利用了一些错误吗?我的同事以“正确”的方式做到了这一点,并且需要在他想要使用界面时随时导入。有任何想法吗?您应该如何创建存在于单独文件中的接口?谢谢!
我尝试使用 asp.net 核心身份实现为我的应用程序使用 SMS OTP 实现一次性注册验证和每日登录。
它是一次性令牌,如果不使用它应该在 15 分钟后过期
用户应再次请求,以防过期或丢失
四处搜索,所有实现都提供了有关基于 MFA 或 Google 身份验证器的验证的详细信息,这种情况略有不同。
令牌不会由服务器生成,也不会由身份验证器应用程序生成。
我需要存储令牌及其生成的时间。
令牌将是 6 位短信。
这个场景更类似于password less auth 这里提到的,但是这种情况下的令牌没有存储,我需要用 Validity 存储它,不确定如何扩展 .net 核心身份以匹配上述要求。
这是相当标准的电话号码认证方式
我知道这不是标准的 SO 格式,但我不知从何开始
我正在尝试创建一个通用的radioButton指令,它将从控制器中获取显示选项:
<cs-radio-field options="gender" ng-model="genderValue"></cs-radio-field>
Run Code Online (Sandbox Code Playgroud)
而选项就像
$scope.gender = { label: "Gender", required:true, valueList: [{ text: "Male", value: "yes" },{text:"Female", value:"no"}] };
Run Code Online (Sandbox Code Playgroud)
该指令定义为:
app.directive("csRadioField", function () {
var templateHtml = function () {
return '<div ng-form="myform">' +
'<div class="control-group" class="{{options.class}}">' +
'<div class="control-label">{{options.label || "Radio"}} {{ options.required ? "*" : ""}} </div>' +
'<div class="controls">' +
'<div class="radio" ng-repeat="(key, option) in options.valueList">' +
'<label> <input type="radio" name="myfield" ng-value="option.value" ng-model="ngModel" ng-required="options.required" />{{option.text}} </label>' +
'</div>' +
'<div class="field-validation-error" data-ng-show="myform.myfield.$invalid && myform.myfield.$dirty"> ' + …Run Code Online (Sandbox Code Playgroud) 该打字机正在生成日期型打字稿在C#中的DateTime类型,我想改变它为"串",但不能够这样做
这是我在.tst尝试过的
string TypeConverter(Type type){
if(type.Name == "Month") return "string";
return type.Name;
}
Run Code Online (Sandbox Code Playgroud)
然后在后一节尝试
//1
export class $Name {$Properties[
public $Name: TypeConverter($Type);]
}
//2
export class $Name {$Properties[
public $Name: TypeConverter;]
}
//3
export class $Name {$Properties[
public $Name: $TypeConverter;]
}
Run Code Online (Sandbox Code Playgroud)
但他们都没有工作
在我的.NET Core项目中,Configure方法中具有以下设置:
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
//services.AddOptions<UploadConfig>(Configuration.GetSection("UploadConfig"));
}
Run Code Online (Sandbox Code Playgroud)
我还没有注册任何东西IOptions,我正在将其注入控制器中
[Route("api/[controller]")]
[ApiController]
public class HelloWorldController : ControllerBase
{
public HelloWorldController(IOptions<UploadConfig> config)
{
var config1 = config.Value.Config1;
}
}
Run Code Online (Sandbox Code Playgroud)
该IOptions是越来越有默认实例解析,和我只知道,当我尝试使用它(当我所期望的价值是不为空)错误。
我能否以某种方式使其失败,说明实例类型未注册或类似原因?我只想尽早发现错误。
c# dependency-injection .net-core asp.net-core asp.net-core-configuration
在控制器内部我每隔一种秒表服务就调用$ interval来进行函数调用.
但问题是当我回到这个路由器时,函数被多次调用,例如,如果我去另一个菜单并回到这里..计时器将被更改两次..如果我再次这样做然后三次.
我已尝试在路由中使用以下3种方法在控制器中具有相同的结果:
$timeout(updateTimer, 1000);
setInterval(function () { $scope.$apply(updateTimer); }, 1000);
$interval(updateTimer, 1000);
Run Code Online (Sandbox Code Playgroud)
当我回到这个页面时,为什么定时器被调用了很多次?
我已经编写了一个从范围字段生成输入字段的指令,一切正常,除非父ng表单保持无效,即使指令中的ng-form无效.
这是我如何检查表单的状态:
<ng-form name="parentForm" class="form-horizontal">
<form-field ng-model="input.name" field="fields[0]" ng-change="changed(input.name)"></form-field>
<form-field ng-model="input.age" field="fields[1]"></form-field>
<pre> parent form: valid : {{parentForm.$valid}}</pre>
</ng-form>
Run Code Online (Sandbox Code Playgroud)
以下是链接功能
var linkFunction = function (scope, element, attrs) {
var fieldGetter = $parse(attrs.field);
var field = fieldGetter(scope);
var template = input(field, attrs); //genrate the template
element.replaceWith($compile(template)(scope)); //replace element with templated code
};
Run Code Online (Sandbox Code Playgroud)
我想问题是我需要编译父元素而不是元素本身来使验证工作,但不知道如何做到这一点
element.replaceWith($compile(template)(scope));
Run Code Online (Sandbox Code Playgroud)
在angularjs中如果我们想要改变状态,$ state.go()和$ state.transitionTo()这些东西甚至在教程中也被很多人引用.但我怀疑的是有人说$ state.go()很好并且也值得推荐.但是,如果你看外部,两个人会做同样的过程.例如$ state.go('^.create')与$ state.transitionTo('create')相同
$stateProvider.state('create',
{
url: '/create',
template: '<div></div>',
controller: 'xyz'
})
Run Code Online (Sandbox Code Playgroud)
我想知道$ state.go()和$ state.transitionTo()的确切区别是什么.
我可以为每个angularjs app设置一个api提供者,像这样
RestangularProvider.setBaseUrl('http://localhost:8080/api');
Run Code Online (Sandbox Code Playgroud)
但我如何设置多个基本网址并有选择地使用它们.我想配置和使用以下两个端点
RestangularProvider.setBaseUrl('http://localhost:8080/api');
RestangularProvider.setBaseUrl('http://localhost:8090/apiws');
Run Code Online (Sandbox Code Playgroud)
我如何用Restangular做到这一点?
下面两个nuget包有什么区别?
Microsoft.AspNetCore.Server.IIS
“使用 AspNetCoreModule 在 IIS 中托管 ASP.NET Core 提供支持。”
Microsoft.AspNetCore.Server.IISIntegration
“用于与 IIS AspNetCoreModule 配合使用的 ASP.NET Core 组件。”
我有下面的一段代码,它给出了分析器警告:
public async Task SendPasswordEmail(string emailId, string link)
{
await _emailSender
.To(emailId)
.Subject(EmailUtilsConstants.PasswordEmailSubject)
.Body(EmailUtilsConstants.PasswordEmailText + link)
.SendAsync();
}
Run Code Online (Sandbox Code Playgroud)
我得到的警告是:
方法“SendPasswordEmail”不需要使用 async/await。
如果该方法不应该使用 async await,那么返回类型应该是什么?Task. 那么下面对分析仪的修复是否正确?
public Task SendPasswordEmail(string emailId, string link)
{
_emailSender
.To(emailId)
.Subject(EmailUtilsConstants.PasswordEmailSubject)
.Body(EmailUtilsConstants.PasswordEmailText + link)
.SendAsync();
return Task.Completed;
}
Run Code Online (Sandbox Code Playgroud) 使用MVC v/s $ .ajax完成POST $.ajax或$http使用XMLHTTPRequest向服务器发送请求之间有什么区别.但ASP.NET MVC使用什么机制
具体来说有什么区别
@using( Html.BeginForm("LoginMethod", "Login", FormMethod.Post) {
// form here
}
Run Code Online (Sandbox Code Playgroud)
和
$.ajax({
url: '....',
type: 'post',
});
Run Code Online (Sandbox Code Playgroud)
我组织的一名高级成员说,我们不应该$.ajax在银行应用程序中使用.那么MVC POST是否更安全?
因此下面的问题
- MVC POST v/s $ .ajax帖子有什么区别
- 为什么/如何/真的是MVC POST更安全吗?
- 为什么我无法在DevTools的网络选项卡中看到MVC POST的详细信息
angularjs ×5
c# ×4
typescript ×3
.net-core ×2
angular ×2
asp.net-core ×2
ajax ×1
asp.net-mvc ×1
async-await ×1
iis ×1
javascript ×1
jquery ×1
promise ×1
restangular ×1
rxjs ×1
typewriter ×1