在我的 app.component.html 中,我想根据当前 url 呈现某些 div 容器。例如
<div *ngIf="'authenticate' === this.currentUrl">
<router-outlet></router-outlet>
</div>
Run Code Online (Sandbox Code Playgroud)
<div *ngIf="'authenticate' !== this.currentUrl" id="wrapper">
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="row extranet-outlet-wrapper">
<router-outlet></router-outlet>
</div>
</div>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我没有使用任何子路由。这是因为,我只想要一个不同的布局来验证组件,其余的保持不变。
这在首次加载时有效,但是当我单击任何[routerLink]视图时,视图不会更新。但是,如果我重新加载屏幕,它就可以工作。问题在于<router-outlet>in的条件渲染app.component.html,我通过删除条件来检查它,它工作得很好。
有人可以帮助我了解这里发生的事情以及如何在不使用子路由的情况下解决此问题。
我正在尝试从服务器下载文件,但该文件并未显示其原始内容,而是显示 [object Object]。
WEB API 核心
[Authorize(AuthenticationSchemes = "Bearer")]
[HttpGet]
public HttpResponseMessage DownloadContractFile(string fileName)
{
string contentRootPath = _hostingEnvironment.ContentRootPath;
var folderName = Path.Combine(contentRootPath, FileHandler.ContractFilePath, Convert.ToInt32(User.Identity.Name).ToString());
var path = Path.Combine(folderName, fileName);
var memory = new MemoryStream();
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
using (var stream = new FileStream(path, FileMode.Open))
{
result.Content = new StreamContent(stream);
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = Path.GetFileName(path);
result.Content.Headers.ContentType = new MediaTypeHeaderValue(FileHandler.GetContentType(path)); // Text file
result.Content.Headers.ContentLength = stream.Length;
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
Angular 代码:服务方法
downloadContractFile(fileName: string) {
const obj: …Run Code Online (Sandbox Code Playgroud) c# asp.net-web-api asp.net-core asp.net-core-webapi angular7
嗨,我正在使用 lodash 进行聚合,但我一直停留在一个地方,我将我的值作为字符串而不是浮点数获取,因此它是连接而不是对值求和。
下面是尝试的方法。
var data = [{extendedPrice: "5151.059", month: "January"},
{extendedPrice: "8921.0336", month: "March"},
{extendedPrice: "2036.9865", month: "April"}];
var sumValue = _.sumBy(data,extendedPrice);
Run Code Online (Sandbox Code Playgroud)
上面的结果
5151.0598921.03362036.9865
预期结果:
16109.0791
任何帮助将非常感激。
我收到此错误消息
指定的值“2019-04-13T00:00:00”不符合要求的格式“yyyy-MM-dd”。
我想将日期/时间更改为日期。
日期时间示例:2019-04-13T00:00:00
我想做的例子:2019-04-13
HTML
<input
class="form-control mr-sm-2"
id="dates"
name="achievement_date"
[(ngModel)]="addItems.achievement_date"
required
type="date"
placeholder="Tournament Date"
/>
Run Code Online (Sandbox Code Playgroud) 每当我单击 HTML 表中的一行时,我都试图调用一个函数,但它不起作用并且没有给出任何错误。
我已经尝试了几件事,在线代码表明我尝试的方式应该可以工作。
我的代码如下:
网址:
<h2>Userstories</h2>
<button (click)="onNewStory()">New Story</button>
<table>
<tr *ngFor="let story of userstories" ng-click="onUpdate(story)" [class.selected]="story === selectedStory">
<td>{{story.id}}</td>
<td>{{story.name}}</td>
<td><button ng-click="onUpdate(story)">Click me!</button></td>
</tr>
</table>
<app-userstory-detail [story]="selectedStory"></app-userstory-detail>
Run Code Online (Sandbox Code Playgroud)
我的 .ts 看起来像这样:
selectedStory: UserStory;
onNewStory() {
var newStory = {id:this.userstories[this.userstories.length-1].id+1, name:"", description:"Deze is nieuw", status:"open", owner:USERS[1]};
this.userstories.push(newStory);
this.selectedStory = newStory;
}
onUpdate(userstory: UserStory): void {
this.selectedStory = userstory;
console.log(this.selectedStory);
}
Run Code Online (Sandbox Code Playgroud)
目前,当我尝试调用 onUpdate 方法时,我的控制台没有打印日志。预期的结果是在日志中看到一些输出,但我不知道它为什么不触发 onUpdate 方法。
我见过与此问题类似的线程,但我没有运气解决它。登录工作成功,但是当我尝试在主页中获取登录用户的数据时,我收到此错误 401 未经授权,邮递员中也显示相同的错误
我的启动.cs
public class Startup
{
private string _connectionString=null;
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//Inject AppSettings
services.Configure<ApplicationSettings>(Configuration.GetSection("ApplicationSettings"));
_connectionString = Configuration["secretConnectionstring"];
//without this it will define for example id to Id
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(options => {
var resolver = options.SerializerSettings.ContractResolver;
if (resolver != null)
(resolver as DefaultContractResolver).NamingStrategy = …Run Code Online (Sandbox Code Playgroud) 即使我没有声明任何宽度属性,我也会在 angular 7 和 primeng 7 中收到以下警告。
width 属性已弃用,请使用 style 来定义 Dialog 的宽度。
有没有人知道如何解决这个问题。
提前致谢
我一遍又一遍地搜索,但也许我的搜索词不正确,因为没有任何结果。我想根据 HTTP 请求的结果动态显示我的 404 组件。
我意识到我可以通过将用户重定向到我的 404 页面来做到这一点,但是有什么方法可以在不更改 URL 的情况下呈现组件?
就像是 /people/<nonexistent id>
谢谢!
我正在使用服务填充 DropDown。服务返回简单的键/值对数组。
打字稿:
public initializeForm(): void {
this.form = this.fb.group({
supplierId: ["", [Validators.required]],
username: ["", Validators.required],
credentials: ["", [Validators.required]],
rating: [""]
})
}
this.adminService.getSuppliers({ active: "true" }).subscribe(res => {
this.suppliers = res;
})
Run Code Online (Sandbox Code Playgroud)
HTML:
<select class="form-control" formControlName="supplierId">
<option>Select Supplier</option>
<option *ngFor="let s of suppliers" [value]="s.supplierId">{{s.supplierName}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
如下图所示,默认选项未设置为页面加载时的选定选项。我希望在页面加载时选择默认选项,就像简单的 HTML 一样,并在我尝试通过在下拉列表中选择默认选项来提交页面时触发所需的字段验证
更新:
如果我将默认选项值设置为 0,它不支持必需的验证,如果我选择默认选项,则认为它有效
我正在尝试APP_INITIALIZER使用我的 angular 应用程序进行简单操作,但出现错误
this.appInits[i] is not a function - 无法弄清楚问题。
这是我的应用程序模块:
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http';
export function onAppInit1(){
return new Promise((resolve,reject) => {
return setTimeout(() => resolve(true), 5000);
})
}
@NgModule({
declarations: [
AppComponent,
SignInComponent
],
imports: [
],
providers: [
{
provide:APP_INITIALIZER,
useFactory:onAppInit1,//getting error
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: InsertAuthTokenInterceptor,
multi: true
}
],
bootstrap: [AppComponent]
})
export …Run Code Online (Sandbox Code Playgroud) angular7 ×10
angular ×5
asp.net-core ×1
asp.net-mvc ×1
bearer-token ×1
c# ×1
dropdown ×1
html ×1
javascript ×1
jquery ×1
jwt ×1
lodash ×1
primeng ×1
typescript ×1