小编use*_*723的帖子

Typescript类型'string'不能分配给类型

这就是我在fruit.ts中所拥有的

export type Fruit = "Orange" | "Apple" | "Banana"
Run Code Online (Sandbox Code Playgroud)

现在我在另一个打字稿文件中导入fruit.ts.这就是我所拥有的

myString:string = "Banana";

myFruit:Fruit = myString;
Run Code Online (Sandbox Code Playgroud)

当我做

myFruit = myString;
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

类型'字符串'不能分配给类型'"Orange"| "Apple"| "香蕉"'

如何将字符串分配给自定义类型Fruit的变量?

javascript typescript angular

96
推荐指数
5
解决办法
10万
查看次数

如何为Spring Boot Controller端点编写单元测试

我有一个示例Spring Boot应用程序,其中包含以下内容

启动主类

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
Run Code Online (Sandbox Code Playgroud)

调节器

@RestController
@EnableAutoConfiguration
public class HelloWorld {
    @RequestMapping("/")
    String gethelloWorld() {
        return "Hello World!";
    }

}
Run Code Online (Sandbox Code Playgroud)

为控制器编写单元测试最简单的方法是什么?我尝试了以下但它抱怨无法自动装载WebApplicationContext

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = DemoApplication.class)
public class DemoApplicationTests {

    final String BASE_URL = "http://localhost:8080/";

    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @Before
    public void setup() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    }

    @Test
    public void testSayHelloWorld() throws Exception{

         this.mockMvc.perform(get("/")
                 .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
                 .andExpect(status().isOk())
                 .andExpect(content().contentType("application/json"));
    }

    @Test
    public void contextLoads() {
    } …
Run Code Online (Sandbox Code Playgroud)

java junit unit-testing spring-test-mvc spring-boot

68
推荐指数
4
解决办法
10万
查看次数

formGroup需要一个FormGroup实例

我在Plunkr上有一个Angular 2 RC4基本表单示例,似乎抛出以下错误(在Chrome DEV控制台中)

这是傻瓜

https://plnkr.co/edit/GtPDxw?p=preview

错误:

browser_adapter.ts:82 EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in ./App class App - inline template:1:7
ORIGINAL EXCEPTION: formGroup expects a FormGroup instance. Please pass one in.
           Example: <form [formGroup]="myFormGroup">

ORIGINAL STACKTRACE:
Error: formGroup expects a FormGroup instance. Please pass one in.
           Example: <form [formGroup]="myFormGroup">

    at new BaseException (https://npmcdn.com/@angular/forms@0.2.0/src/facade/exceptions.js:27:23)
    at FormGroupDirective._checkFormPresent (https://npmcdn.com/@angular/forms@0.2.0/src/directives/reactive_directives/form_group_directive.js:110:19)
    at FormGroupDirective.ngOnChanges (https://npmcdn.com/@angular/forms@0.2.0/src/directives/reactive_directives/form_group_directive.js:39:14)
    at DebugAppView._View_App0.detectChangesInter
Run Code Online (Sandbox Code Playgroud)

angular2-forms angular2-formbuilder angular

40
推荐指数
5
解决办法
10万
查看次数

Spring MVC REST不符合JAX-RS.有关系吗?

我在Spring MVC REST方面有很好的经验,并提供了几个可靠的项目.我的问题是关于JAX-RS合规性.这是否重要,因为Spring将继续存在,我无法预见(也没有理由)不得不在很短的时间内从Spring MVC REST转移到Jersy或任何其他JAX-RS.任何应该迫使我考虑使用JAX-RS实现而不是Spring MVC REST的东西?

java rest spring jax-rs spring-mvc

25
推荐指数
1
解决办法
2万
查看次数

如何在Angular 2中迭代Object属性

这是我的对象(它有n个动态键.我在下面的例子中只显示了两个)

let obj = {
abc:["some text", "some more text"],
xyz:["more text", "what do you think?", "I'm tired now"]

}
Run Code Online (Sandbox Code Playgroud)

这是我尝试循环抛出上面的内容并打印所有值

 <div *ngFor='let item of obj ; let i = index;'>
            <p *ngFor="let value of obj.i">{{value}}
 </div>
Run Code Online (Sandbox Code Playgroud)

但上述似乎不起作用.我做错了什么,语法是正确的?

javascript iteration loops ngfor angular

22
推荐指数
3
解决办法
2万
查看次数

如何在Angular 2 RC5中使用HashLocationStrategy进行引导

我正在从Angular 2 RC4升级到RC5

这是我目前的主要内容

import {enableProdMode} from '@angular/core';
import {bootstrap}    from '@angular/platform-browser-dynamic';
import {AppComponent} from './app/app.component';
import {AppRoutes} from './app/app.routes';
import { provideRouter } from '@angular/router';
import { XHRBackend } from '@angular/http';
import { HTTP_PROVIDERS } from '@angular/http';
import { LocationStrategy,
         HashLocationStrategy } from '@angular/common';
import {disableDeprecatedForms, provideForms} from '@angular/forms';
import {provide} from '@angular/core';

enableProdMode();
bootstrap(AppComponent, [
  disableDeprecatedForms(),
  provideForms(),
  provideRouter(AppRoutes)
  ,HTTP_PROVIDERS,
  provide(LocationStrategy, {useClass: HashLocationStrategy})

])
  .catch(err => console.error(err));
Run Code Online (Sandbox Code Playgroud)

这是我更新的main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule); …
Run Code Online (Sandbox Code Playgroud)

typescript angular

19
推荐指数
1
解决办法
1万
查看次数

错误:模块'DynamicFormModule'导出的意外值'undefined'

Angular2具有动态生成表单的能力(模型驱动表单),而不是手动生成表单(模板驱动).

我有动态表单的变体,其中整个表单生成功能作为模块公开(Angular RC5).

但它打破了以下错误(出现在开发控制台中)

VM849:20 Error: Error: Unexpected value 'undefined' exported by the module 'DynamicFormModule'
Run Code Online (Sandbox Code Playgroud)

这是傻瓜

动态形式作为模块Plunkr

module angular

14
推荐指数
2
解决办法
1万
查看次数

如何使用Javascript或JQuery在HTML中突出显示输入文本字段的一部分

我正在HTML中的自由键入的输入文本字段上执行某种形式的验证.有没有办法使用JQuery或JavaScript在输入文本字段中突出显示某些单词或短语(基于某些标准)?

html javascript validation jquery

12
推荐指数
1
解决办法
2万
查看次数

Angular ng-change for select不调用声明的方法

我有以下html表单select语句

<select ng-change="setBillGroup()" ng-model="bill.groupId" class="span8" ng-options="d.id as d.name for d in groups"></select>
Run Code Online (Sandbox Code Playgroud)

和js

myApp.controller('myAppController', function($scope, myAppService) {

.....
function setBillGroup(){
 console.log("setBillGroup method called!");
    ......
 }

....
});
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,当我在表单中选择某个或另一个时,似乎永远不会调用setBillGroup().

html javascript select angularjs

11
推荐指数
1
解决办法
2万
查看次数

Git add命令失败,说"文件名太长"

我初始化了一个git存储库,用于添加Oracle Weblogic服务器的本地实例(是!),以便使用git对其进行版本化.

oracle文件位于c:\ Oracle中.所以我需要将相同的内容添加到git中

我发出了以下命令

git init(在c:\中有Oracle目录)

在c:\中添加了一个.gitignore目录,并忽略了c:\中除Oracle之外的所有目录

然后运行'git status'来查看状态.正如所料,它显示了以下内容

C:\>git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
#       Oracle/
nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)

现在,我做了一个git add*上面的命令按预期抛出了一些详细的输出,显示了正在添加的文件并以下面结束(命令输出的尾部显示在下面)

....
base_domain/servers/AdminServer/tmp/.appmergegen_1387484701373_liferay-portal-6.
1.30-ee-ga3-20130812170130063.war/html/VAADIN/themes/runo/tree/tree.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in Oracle/Middleware/user_projects/domains/ …
Run Code Online (Sandbox Code Playgroud)

git version-control

10
推荐指数
3
解决办法
6971
查看次数