我在我的项目angular5中使用ng-select 2.0.0,就像在 这个链接中一样 ,我可以从api rest spring boot获得结果,但是当我点击ng-select时我遇到了一个问题我得到了这个错误:
ERROR TypeError: Object(...) is not a function
at NgDropdownPanelComponent.ngOnInit (ng-select.js:1450)
at checkAndUpdateDirectiveInline (core.js:12352)
at checkAndUpdateNodeInline (core.js:13876)
Run Code Online (Sandbox Code Playgroud)
而且我也不能选择我想要的信息(在这种情况下属性'nom'),就像ng select被阻止或者像这样的东西.
这是我的project.component.html代码
<ng-select *ngIf="_listClients"
[items]="listClient"
bindLabel ="nom"
bindValue ="id"
[(ngModel)]="selectedPersonId">
</ng-select>
<p>
Selected city ID: {{selectedPersonId | json}}
</p>
Run Code Online (Sandbox Code Playgroud)
这是文件project.component.ts
import {Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {ProjetService} from '../../../../../service/projet.service';
import {Projet} from '../../Models/Projet';
import { ModalDirective } from 'ngx-bootstrap/modal';
import 'rxjs/add/operator/map';
import {ClientService} from '../../../../../service/client.service';
@Component({
selector: 'app-projects',
templateUrl: './projects.component.html', …Run Code Online (Sandbox Code Playgroud) twitter-bootstrap angular2-template bootstrap-4 angular angular5
我在 angular5 简单项目(前端)和后端(弹簧引导)中工作,我想向带有 2 个参数 idPerson 和 idProject 的 api rest 发送 post 请求,因此 api rest 可以影响项目到选定的人,我尝试在带有 POST 的服务中执行此操作,但这是不可能的。
这是 ProjectService.ts 的代码
addProjToClient(idPerson:number,idProject:number){
if(this.authService.getToken()==null) {
this.authService.loadToken();
}
return this.http.post(this.host+"/saveProjectToClient",idPerson,idProject,{headers:new HttpHeaders({'Authorization':this.authService.getToken()})});
}
Run Code Online (Sandbox Code Playgroud)
不可能在 http Post 中发送超过 2 个参数,我使用 httpClient 。
关于如何做到这一点的任何想法?
我正在使用 angular5 ,我无法将 *dropdownMenu 与 *ngFor 一起使用,我收到此错误:
ng : Can't have multiple template bindings on one element . Use only one attribute named template or prefixed with *
Run Code Online (Sandbox Code Playgroud)
这是代码:
<div class="btn-group" dropdown>
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle" (click)="ListUsers()">
List of users <span class="caret"></span>
</button>
<ul *dropdownMenu class="dropdown-menu" role="menu" *ngFor="let c of listUsers">
<li role="menuitem"><a class="dropdown-item">{{c.Firstname}} {{c.lastName}}</a></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我想先开发一个以 angular4 为前端,spring boot 为后端的 Web 应用程序,然后再创建 android 版本。
在谷歌搜索我发现有很多方法,第一个是创建一个 Spring boot 项目,其中包含一个 angular 4 文件夹(使用 angular CLI 生成),这意味着总共一个项目。
第二个:完全分离2个项目,一个用于spring,另一个用于angular4,客户端将使用api Rest与spring工具进行通信。
哪一种是最好的方法?
提前致谢。
我要在官方链接中发现 SweetAlert ,所以我想在我的应用程序 angular5 中使用它。
我是这样安装的:
npm install sweetalert --save
Run Code Online (Sandbox Code Playgroud)
我已将它导入到我的组件中:edit-client.component 与此:
import swal from 'sweetalert';
Run Code Online (Sandbox Code Playgroud)
这是我尝试使用的文件 editClient.component.ts :
import swal from 'sweetalert';
Component({
selector: 'app-edit-clients',
templateUrl: './edit-clients.component.html',
styleUrls: ['./edit-clients.component.scss']
})
export class EditClientsComponent implements OnInit {
EditClient(){
this.clientService.updateClient(this.client)
.subscribe(data=>{
console.log(data);
swal('mise a jour effecture !');
this.router.navigate([ '../../../list' ], { relativeTo: this.activatedRoute });
},err=>{
console.log(err);
alert("Probleme");
})
}
}
Run Code Online (Sandbox Code Playgroud)
但是在运行这个例子时,我看不到警报,而是收到一个错误:
RROR TypeError: sweetalert_1.default is not a function
at SafeSubscriber.eval [as _next] (edit-clients.component.ts:39)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:240)
at SafeSubscriber.next (Subscriber.js:187) …Run Code Online (Sandbox Code Playgroud) 我正在尝试检查用户名在spring-boot中是否唯一。我想将结果作为JSON对象发送。这是REST控制器
@RequestMapping(value="/checkEmailUnique",method=RequestMethod.POST)
public String checkEmailUnique(@RequestBody String username){
AppUser app = userRepo.findByUsername(username);
if(app!=null){
// I want to return somthing like emailNotTaken: true
}
else{
// and here : emailNotTaken: false
}
}
Run Code Online (Sandbox Code Playgroud)
我想获得角度结果,以便在组件中显示错误消息。我怎样才能做到这一点?
角边
客户服务
checkEmailNotTaken(email:string){
if(this.authService.getToken()==null) {
this.authService.loadToken();
}
return this.http.post(this.host+
"/checkEmailUnique/",{email},{headers:new HttpHeaders({'Authorization':this.authService.getToken()})});
}
Run Code Online (Sandbox Code Playgroud)
在client.component.ts中
ngOnInit() {
this.form = this.formBuilder.group({
prenom: ['', Validators.required],
nom: ['', Validators.required],
tel: ['', Validators.required],
cin: ['', Validators.required],
username: ['', Validators.required , Validators.email , this.validateEmailNotTaken.bind(this)],
passwordG: this.formBuilder.group({
password: ['',[Validators.required,Validators.minLength(9)]],
Confirmationpassword : ['',[Validators.required,Validators.minLength(9)]]
}, {validator: passwordMatch})
}); …Run Code Online (Sandbox Code Playgroud) angular ×5
angular5 ×5
java ×2
spring ×2
bootstrap-4 ×1
frontend ×1
httpclient ×1
spring-boot ×1
spring-data ×1
sweetalert ×1
sweetalert2 ×1