我正在尝试使用maven开发一个应用程序,其中Spring Boot用于后端,Angular 2用于前端.
角2前端src/main/resources/static位于项目的目录中.
当我http://localhost:8080/在浏览器中输入URL时,一切都很好:我可以访问角度2前端,前端可以完美地与其余的api通信.我的angular 2路由工作正常:当我点击前端的链接时,我走右页,浏览器url栏显示正确的东西(即.http://localhost:8080/documents)
但问题是当我尝试在浏览器中直接写入相同的URL时.Spring接管前端并表示没有映射/documents.
有没有办法告诉spring boot只能"监听" /api/*URL并将所有其他人"重定向"到前端?
这是我的Spring Controller类:
@RestController
@RequestMapping("/api")
public class MyRestController {
@Autowired
private DocumentsRepository documentRepository;
@CrossOrigin(origins = "*")
@RequestMapping(value = "/documents/list",
method = RequestMethod.GET,
produces = "application/json")
public Iterable<RfDoc> findAllDocuments() {
return documentRepository.findAll();
}
}
Run Code Online (Sandbox Code Playgroud)
这是主要的应用程序类:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的app.route.ts:
import { provideRouter, RouterConfig } from '@angular/router';
import { DocumentComponent } from …Run Code Online (Sandbox Code Playgroud) 我有一个角度2工具来监控服务器,刚开始测试.当我尝试模拟httpService时,我不知道如何模拟Rest-API,所以我在线查看,修复了一些错误,现在我已经陷入了这个错误.
这里错误:
Chrome 53.0.2785 (Windows 10 0.0.0) HttpServiceFront should use an HTTP call Servers FAILED
Error: No provider for HttpServiceFront!
at NoProviderError.Error (native)
...
at drainMicroTaskQueue (webpack:///~/zone.js/dist/zone.js:368:0 <- config/karma-test-shim.js:6854:36)
Chrome 53.0.2785 (Windows 10 0.0.0): Executed 2 of 3 (1 FAILED) (skipped 1) (0.268 secs / 0.057 secs)
Run Code Online (Sandbox Code Playgroud)
这是我的测试用例:
import {
ResponseOptions,
Response,
Http,
BaseRequestOptions,
RequestMethod
} from '@angular/http';
import {
TestBed, fakeAsync, inject
} from '@angular/core/testing';
import { HttpServiceFront } from '../app/services/httpServiceFront';
import { MockBackend, MockConnection } from '@angular/http/testing';
const …Run Code Online (Sandbox Code Playgroud) 我在角度2中使用HTTP请求.我想在获得HTTP响应时调用下一个进程.
示例:在表单中 选择选项值来自HTTP get Request.我希望表单页面正在加载,直到我收到select选项的响应.
获得功能
getSelectOptionValue(): any {
let area_list_url = '/select_option_list/';
this.urlGet(area_list_url).subscribe(
(response) => {
let data = response.text() ? response.json() : [{}];
if (data) {
Constant.areaList = data;
}
}
);
}
return JSON.stringify(Constant.areaList);
}
Run Code Online (Sandbox Code Playgroud)
GET功能
urlGet(url: string) {
return this._http.get(Constant.hostUrl + url, {headers: GlobalUtils.head})
.map((res)=> {
if (res.status === 200) {
console.log(res);
return res;
} else if (res.status = 201) {
return res;
}
}).catch((error)=> {
console.log(error);
if (error.status === 400) …Run Code Online (Sandbox Code Playgroud) 我看到我被允许使用了
argument: MyClassName(a,b)
Run Code Online (Sandbox Code Playgroud)
以及
argument: new MyClassName(a,b)
Run Code Online (Sandbox Code Playgroud)
我想new在Dart中理解是可选的吗?或者这两个回归完全不同的东西?
我有两个要素.当一个元素悬停时,应删除另一个元素的一个类.
import {Component} from '@angular/core'
@Component({
selector:'display'
template:`
<div #myname />
<p class="DN"> My name is Dude...</p>
`
})
export class DisplayComponent{
}
Run Code Online (Sandbox Code Playgroud)
当div悬停类DN的p标签应该被删除.
我正在写angular2应用程序.我需要所有按钮并选择禁用,然后我需要启用它们.我想通过使用我的类字段但禁用但没有运气来做到这一点.我有这个代码:
@Component({
selector: 'my-app',
template:`
<h1>Disable Enable</h1>
<h2> this is a disabled select </h2>
<select type="number" [(ngModel)]="levelNum" (ngModelChange)="toNumber()" disabled>
<option *ngFor="let level of levels" [ngValue]="level.num">{{level.name}}</option>
</select>
<h2> this is a disabled button </h2>
<button type="button" class="btn btn-default {{butDisabled}}">Disabled</button>
<h2> Why can't I disable the select the same way? </h2>
<select type="number" [(ngModel)]="levelNum" (ngModelChange)="toNumber()" class="{{butDisabled}}">
<option *ngFor="let level of levels" [ngValue]="level.num">{{level.name}}</option>
</select>
`,
})
export class AppComponent {
butDisabled = "disabled";
levelNum:number;
levels:Array<Object> = [
{num: 0, name: "AA"},
{num: 1, …Run Code Online (Sandbox Code Playgroud) 如果我使用Json.Net,则将Dictionary序列化为:
{
"key": "value",
"key2": "value2",
...
}
Run Code Online (Sandbox Code Playgroud)
如何将其转换为Typescript对象?我主要想要一个typeof值数组
我有一个选择列表,使用[ngValue]绑定到我的组件上的Person属性.当我更改选择时,underyling selectedPerson属性将按预期更新.但是,如果我在代码中更改了所选人员,则select在初始化时不会默认为所选人员,也不会更新.
对我所缺少的任何帮助将不胜感激.这是我的代码......
import {Component, OnInit, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import { FormsModule } from '@angular/forms';
@Component({
selector: 'my-app',
template: `
<form>
<select [(ngModel)]="selectedPerson"
name="selectedPerson">
<option [ngValue]="null">Please choose...</option>
<option *ngFor="let p of people"
[ngValue]="p"
[attr.selected]="p.personId === selectedPerson?.personId ? true : null ">{{p.name}}</option>
</select>
<p>The selected person is {{selectedPerson?.name}}</p>
<button type="button" (click)="selectJane()">Select Jane</button>
<button type="button" (click)="clearSelection()">Clear Selection</button>
</form>`,
})
export class App implements OnInit {
public ngOnInit() {
this.people = [
{ personId: 1, name: "Tom" },
{ …Run Code Online (Sandbox Code Playgroud) 我刚刚用了大部分时间搞清楚这个.
这是问题所在:习惯在Bamboo中使用MSTest,它运行正常.
使用Asp.Net.Core的第一个项目,带有XUnit测试,需要在Bamboo中进行设置.
Bamboo不支持XUnit测试结果xml文件..叹气......
该怎么办?
当http.get方法更新我时,我正在创建表行...接收数据我使用角度2版本中的JS/jquery创建表行.
我的代码:
<tr>
<td>2</td>
<td>BAJAJ-AUTO</td>
<td>14.284%</td>
<td>27/12/2013 12:00 am</td>
<td>30/12/2013 12:00 am</td>
<td>1935</td>
<td>30/12/2013 12:00 am</td>
<td>1935</td>
<td>31/12/2013 12:00 am</td>
<td>2120</td>
<td><button class="btn btn-default" onclick="processAdvise('BAJAJ-AUTO')">Process Advise</button></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
所以最后一个td- 有一个按钮,它将调用我的角度2函数来处理它 - 这个代码即使在函数的开头也不会到达
我也试过这个无济于事:
(click) 为角2onclick 并使用脚本标记将该函数保存在同一HTML模板中