我正在尝试更新 Angular 5 中的子组件,但无法正常工作。
我的家庭组件通过服务获取数据。
它有一个名为 getTopicToFilter 的函数,该函数由另一个组件更新。这工作正常,并为我提供了TopicId一个@Output EventEmitter.
我的问题是文章没有在子组件中更新
export class HomeComponent implements OnInit {
loading = true;
topics: Observable<Topic[]>;
posts: Observable<Post[]>;
public constructor(
private blogService: BlogService
) { }
ngOnInit() {
this.posts = this.blogService.getPostsByTopic().share()
// Note that the forkJoin gets other, unrelated data that I have removed from the question
Observable.forkJoin([
this.posts
]).subscribe(
response => { },
error => {
console.log('An error occurred:', error);
},
() => {
this.loading = false;
});
}
getTopicToFilter(topicId) …Run Code Online (Sandbox Code Playgroud) 我在Angular 5中遇到麻烦.
我想支持以下网址
这个工作:
/post
Run Code Online (Sandbox Code Playgroud)
这个没有,它将我重定向到我的NotFoundComopnent
/post/test-post-title
Run Code Online (Sandbox Code Playgroud)
我的AppRoutingModule
export const routes: Routes = [
{ path: 'post', loadChildren: 'app/feature/post/post.module#PostModule' },
{ path: '**', component: NotFoundComponent },
];
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
我的PostRoutingModule:
const routes: Routes = [
{
path: '',
component: PostHomeComponent,
children: [
{
path: ':slug', component: PostDetailComponent
}
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class PostRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
更新以显示PostDetailComponent
export class PostDetailComponentimplements OnInit {
constructor(
private route: ActivatedRoute
) {}
ngOnInit() {
const …Run Code Online (Sandbox Code Playgroud) 我试图基于此文章在.net core 2.1中运行基于策略的授权:https : //docs.microsoft.com/zh-cn/aspnet/core/security/authorization/policies?view= aspnetcore-2.1
但是,我似乎无法解决。
在下面的示例中,我注释掉了context.suceeed行,因此我以为对usercontroller的api调用将失败。
但是我的API调用已被接受。
我究竟做错了什么?
这是我的startup.cs
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IAuthorizationHandler, VerifyAuthCookieHandler>();
services.AddAuthorization(options =>
{
options.AddPolicy("VerifyAuthCookie", policy =>
policy.Requirements.Add(new VerifyAuthCookieRequirement()));
});
services.AddMvcCore().AddJsonFormatters();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的经理
public class VerifyAuthCookieHandler : AuthorizationHandler<VerifyAuthCookieRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
VerifyAuthCookieRequirement requirement)
{
//context.Succeed(requirement);
return Task.CompletedTask;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的要求:
public class VerifyAuthCookieRequirement : IAuthorizationRequirement
{
public VerifyAuthCookieRequirement()
{
}
}
Run Code Online (Sandbox Code Playgroud)
最后,我的控制器:
[Route("api/[controller]")]
[Authorize(Policy = …Run Code Online (Sandbox Code Playgroud) 我有一个 Angular 应用程序,它调用一个 REST API,它可以返回类似于此图像的错误。
如何在 API 调用中解析此内容以提取错误消息?
我正在使用以下代码:
this.authService.login(this.userLogin)
.pipe(first())
.subscribe(
data => {
this.router.navigate([this.returnUrl]);
},
error => {
console.log(error)
this.alertService.validationError(error.error);
this.isRequesting = false;
});
Run Code Online (Sandbox Code Playgroud)
但是 error.error 给了我一个数组,我不知道其中的键可能是什么 - 在图像中它是 login_failure 但它可能是任何东西,我不知道如何解析它。
我无法从Angular 6应用程序的子组件中获取路由参数
我在app-routing.module中设置了以下路由:
{
path: 'item/:id',
component: ItemLayoutComponent,
children: [
{ path: '', redirectTo: 'inbox', pathMatch: 'full' },
{ path: 'inbox', loadChildren: './feature/inbox/inbox.module#InboxModule' }
]
},
Run Code Online (Sandbox Code Playgroud)
然后在我的inbox-routing-module.ts中:
{
path: '',
component: InboxComponent,
children: [
{ path: '', redirectTo: 'messages', pathMatch: 'full' },
{
path: 'messages', component: MessagesComponent
},
]
}
Run Code Online (Sandbox Code Playgroud)
这使我可以使用一个类似于以下网址的URL到达我的消息组件:
item/5200/inbox/messages
Run Code Online (Sandbox Code Playgroud)
我的问题是,在我的ItemLayoutComponent中,我可以使用以下代码获取id字段的值(在本例中为5200):
this.route.snapshot.paramMap.get('id')
Run Code Online (Sandbox Code Playgroud)
但是,我需要在MessagesComponent中使用此ID的值。目前,相同的代码使我为空。
我有一个ASP.NET 4.0页面,我试图在提交表单后重置到顶部,以显示验证摘要.
我正在使用Ajax,我有一个包含以下简化代码的母版页:
<form id="Form1" runat="server" target="_top" >
<asp:ScriptManager runat="server" ID="SM1" />
<asp:UpdatePanel runat="server" ID="UP1" >
<ContentTemplate>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</form>
Run Code Online (Sandbox Code Playgroud)
我的内容页面如下所示:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ValidationSummary ID="vs1" runat="server" ValidationGroup="ValidateForm" DisplayMode="BulletList"
CssClass="ValidationSummary" ShowSummary="true" ShowMessageBox="false" />
< ... Form Field ... >
< ... Form Field ... >
< ... Form Field ... >
< ... Form Field ... >
...
< ... Form Field ... >
<asp:ImageButton ID="btnSaveChanges" runat="server" ImageUrl="/Assets/Images/btn-AdminSaveChanges.png"
ValidationGroup="ValidateForm" CausesValidation="false" OnClick="btnSaveChanges_Click" />
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
当前发生的情况是,当用户到达表单底部并点击提交按钮时,页面将保持原样并且验证摘要不可见.我想在验证错误时将页面重置为顶部.我已经尝试在内容页面标题中将maintaincrollposition设置更改为false,但它似乎没有做任何事情.
任何帮助将不胜感激!
我正在使用 FullCalender 并希望更改我的月和周视图中的样式,以便所选日期不是黄色阴影,而是它周围有一个粗边框。
我试过了
.fc-state-highlight, .fc-unthemed .fc-today {
background-color: white;
border: 3px solid #f26122;
}
Run Code Online (Sandbox Code Playgroud)
但这只是在表格单元格的顶部和左侧绘制了一个边框:

我有一组Angular形式的动态复选框:
<div class="form-check" *ngFor="let topic of topics">
<input class="form-check-input" (change)="onChange(f)" #f type="checkbox" [value]="topic.name" name="topicgroup">
<label class="form-check-label" style="font-weight: normal">
{{topic.name}}
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
在我的编辑组件中,如何将它们设置为已选中?
我有一个包含所有选项的数组,以及检查哪个选项:
Topics: string[] = ['Topic1', 'Topic2', 'Topic3', 'Topic4', 'Topic5'];
selectedTopics: string[] = ['Topic1', 'Topic2'];
Run Code Online (Sandbox Code Playgroud)
我如何在我的html页面上反映出来?
更新:这是我的onChange函数:
onChange(f) {
if (this.selectedTopics.indexOf(f.value) == -1) {
this.selectedTopics.push(f.value);
} else {
this.selectedTopics.splice(this.selectedTopics.indexOf(f.value), 1);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将登录用户的详细信息提供给我的应用程序。我有以下代码在Angular 5中可用,但在Angular 6中不起作用,因为rxjs 6中缺少.share()函数
我需要.share()函数吗?关于rxjs 6的更改,我的代码看起来还可以吗?
export class UserService {
readonly baseUrl = `${environment.apiUrl}/auth`;
private loggedIn = false;
private currentUserSubject = new BehaviorSubject<LoggedInUser>({} as LoggedInUser);
currentUser = this.currentUserSubject.asObservable().share();
constructor(private http: HttpClient) { }
login(userLogin: UserLogin) {
return this.http.post<any>(this.baseUrl + '/login', { username: userLogin.email, password: userLogin.password })
.subscribe(result => {
localStorage.setItem('auth_token', result.auth_token);
this.setCurrentUser();
return true;
});
}
setCurrentUser(): void {
if (localStorage.getItem("auth_token")) {
let jwtData = localStorage.getItem("auth_token").split('.')[1]
let decodedJwtJsonData = window.atob(jwtData)
let decodedJwtData = JSON.parse(decodedJwtJsonData)
this.currentUserSubject.next(
{
firstName: decodedJwtData.given_name,
id: decodedJwtData.id, …Run Code Online (Sandbox Code Playgroud) 我有以下一段代码,它适用于旧版 IOS 应用程序,但现在不再适用于 xcode 9:
我收到的错误是:
'ContentMode' is not a member type of 'UIView'
Run Code Online (Sandbox Code Playgroud)
这是代码:
import Foundation
struct ImageViewLayout {
static func frameForImageWithSize(_ image: CGSize, previousFrame: CGRect, inContainerWithSize container: CGSize, usingContentMode contentMode: UIView.ContentMode) -> CGRect {
let size = sizeForImage(image, previousSize: previousFrame.size, container: container, contentMode: contentMode)
let position = positionForImage(size, previousPosition: previousFrame.origin, container: container, contentMode: contentMode)
return CGRect(origin: position, size: size)
}
Run Code Online (Sandbox Code Playgroud) angular ×6
asp.net ×2
asp.net-core ×1
c# ×1
css ×1
fullcalendar ×1
ios ×1
javascript ×1
swift ×1
typescript ×1
uiview ×1