小编Kly*_*ner的帖子

无法在HTML中处理Typescript枚举

我使用Typescript创建了一个枚举,用于MyService.service.ts MyComponent.component.ts和MyComponent.component.html.

export enum ConnectionResult {
    Success,
    Failed     
}
Run Code Online (Sandbox Code Playgroud)

我可以轻松地从MyService.service.ts获取并比较定义的枚举变量:

this.result = this.myService.getConnectionResult();

switch(this.result)  
{
    case ConnectionResult.Failed:
         doSomething();
         break;
    case ConnectionResult.Success:
         doSomething();
         break;
}
Run Code Online (Sandbox Code Playgroud)

我还想使用枚举在我的HTML中使用*ngIf语句进行比较:

<div *ngIf="result == ConnectionResult.Success; else failed">
            <img src="../../assets/connection-success.png" height="300px" class="image-sign-style" />
</div>
<ng-template #failed>
       <img src="../../assets/connection-failed.png" height="300px" class="image-sign-style" />
</ng-template>
Run Code Online (Sandbox Code Playgroud)

代码编译但浏览器给我一个错误:

无法读取未定义的属性

在此输入图像描述

使用以下html指示错误行:

在此输入图像描述

有谁知道为什么不能像这样接近枚举?

html enums typescript angular

47
推荐指数
5
解决办法
3万
查看次数

Angular:无法获得/

我正在尝试打开,构建和运行其他人的Angular 4项目,但是当我按照自己的方式运行时,我无法查看项目.我不知道出了什么问题或我现在应该做些什么.我已经拥有了使用NPM和NodeJS的一切

我采取的步骤是:

  • 打开项目
  • npm安装
  • 服务

该项目以正确的方式编制.(我有一个自己的Angular应用程序,我知道这是怎么样的)控制台显示:

'**NG Live Development Server正在侦听localhost:4200,在http:// localhost:4200**' 上打开浏览器.

然后,当我打开一个Web浏览器时,我导航到localhost:4200并显示了一个带有以下文本的网页:

'不能获取 /'

在控制台上有以下文字:

'GET http:// localhost:4200/404(Not Found)'

该项目应该可以正常工作,但我无法导航到网页上的工作URL.路由设置是另一种方式,因为我习惯这样做.在app.module.ts中实现了以下内容:

app.module.ts

const appRoutes: Routes = [
{ path: '',   redirectTo: 'tree', pathMatch: 'full' },
{ path: 'admin', component: AdminPanelComponent, canActivate: [AuthGuard],
children: [{path:'', component: PanelComponent},{path: 'add', component: 
AddTreeComponent}, {path:'manage-trees', component:ManageTreesComponent}, 
{path:'manage-users', component: ManageUsersComponent}, {path:'view-trees', 
component: ViewTreeComponent}]},
{path:'tree', component: TreeComponent},
{path:'error', component: ErrorComponent},
{path:'unauthorized', component: UnauthorizedComponent},
{path:'login', component: LoginComponent},
{path:'entire-tree', component: EntireTreeComponent},
{ path: '**', component: …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript angular

27
推荐指数
6
解决办法
5万
查看次数

如何在Angular 2和4中设置WOW.js?

我试图让WOW.js在我的Angular项目中工作,但它还没有工作.我没有使用webpack所以我认为下一个线程没有回答我的问题:如何在Angular 2 Webpack中使用WOW.js?.

到目前为止我采取的步骤:

  1. 我安装了wow.js模块.

npm install wowjs

  1. 我将wowjs文件添加到'.angular-cli.json'.

    "styles":["../ node_modules/wowjs/css/libs/animate.css"],

    "scripts":["../ node_modules/wowjs/dist/wow.js"]

然后,我在其中一个标题中添加了哇效果.

<h1 class="wow slideInLeft" data-wow-duration="2s">Wow effect!</h1>
Run Code Online (Sandbox Code Playgroud)
  1. 我接下来要做的就是重建和服务我的项目.

建立

服务

  1. 还没有惊人的效果.有人知道我要做什么吗?

javascript wow.js angular

9
推荐指数
1
解决办法
3978
查看次数

如何阻止PhpStorm索引我的`excluded`目录?

在PhpStorm 2018.1.6中,我有一个x我已经排除使用的目录Settings | Directories -> Exclude directory x.PhpStorm负责处理我排除的大多数目录,但不包括这个目录.在我编辑/创建PHP测试时,PhpStorm一直忙于索引此目录.

在此输入图像描述

目录x是导入项目的一部分.

PhpStorm是否有任何理由可以排除被排除的目录并对其进行索引?索引过程需要永远.

在此输入图像描述

php indexing phpstorm

6
推荐指数
1
解决办法
468
查看次数

如何使用引导程序 btn-block 设置边距?

我想在使用引导程序的 btn-block 时为我的按钮添加边距。不幸的是,它没有做我想做的事,因为按钮不会缩小。按钮从它的 div 中消失。

在这段文字下,您可以看到我的意思。两个按钮都包含引导程序“btn-block”元素。上面的按钮有一个边距。

<div>
    <button type="button" class="btn btn-block btn-default" style="margin:0px 10px 0px 10px;">No</button>
    <button type="button" class="btn btn-block black-button">Yes</button>
</div>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

有人知道如何以按钮保留在上述 div 中的方式向按钮应用边距吗?

css twitter-bootstrap

4
推荐指数
1
解决办法
2729
查看次数

如何让茉莉花等待一个承诺被解决或拒绝?

我有一个特定的功能,我正在尝试使用 Angular 进行测试。此函数返回一个承诺。虽然在我的测试中我对 promise 结果设定了期望,但 Jasmine 不会等待 promise 被解决或拒绝。

警告:

错误:“规范‘测试’没有预期。”

测试函数定义如下:

public validate(file: File): Promise<any[]> {
    return new Promise((resolve, reject) => {
      // Code
    }
}
Run Code Online (Sandbox Code Playgroud)

测试代码:

it(
    test.description,
    fakeAsync(() => {
      // Doesnt wait for the following promise result:
      importValidator.validate(test.testFile).then(
        resolveValue => {
          expect(Array.isArray(resolveValue)).toBe(true);
        },
        onReject => {
          expect(test.resolve).toBeFalsy();
        }
      );
    })
  );
Run Code Online (Sandbox Code Playgroud)

如何让 Jasmine 在测试期间等待验证承诺被解决/拒绝?当我让测试因预期未发生的事情而失败时,它实际上会在afterAll.

testing promise jasmine angular

3
推荐指数
1
解决办法
1878
查看次数

在段落旁边绘制圆形线的最简单方法是什么?

我希望在文本旁边有一条垂直线.我可以使用'border-left'在左边画一条垂直线,但我还没有找到如何围绕它的角落.下图显示了它应该如何:

在此输入图像描述

html css

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

Spring boot Bean 异常:无法确定数据库类型 NONE 的嵌入式数据库驱动程序类

我正在尝试运行由其他人制作的 Spring Boot 应用程序。我试图将我的本地数据库附加到应用程序,但是当我运行它时,它给出了以下错误;

org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration”的bean时出错:自动装配依赖项的注入失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class] 中定义名称为“dataSource”的 bean 创建错误:通过工厂方法的 Bean 实例化失败; 嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [javax.sql。DataSource]:工厂方法“dataSource”抛出异常;嵌套异常是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:无法确定数据库类型 NONE 的嵌入式数据库驱动程序类。如果您想要一个嵌入式数据库,请在类路径上放置一个受支持的数据库。如果您有要从特定配置文件加载的数据库设置,您可能需要激活它(当前没有配置文件处于活动状态)。

我是新手,我无法找出问题所在。一些细节:

其中 xxx = 数据库的名称。

工作台:

Name: Local instance wampmysqld64
Host: localhost
Port: 3306
Server: MySQL Community Server (GPL)
Version: 5.7.18-log
Connector: C++ 1.1.4 
Login User: root
Current User: root@localhost
SSL: Disabled
Run Code Online (Sandbox Code Playgroud)

服务器已启动并正在运行。

编辑

pom.xml

<project>

<modelVersion>4.0.0</modelVersion>

<groupId>****</groupId>
<artifactId>****</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.6.RELEASE</version>
</parent>

<dependencies>
    <dependency>
      <groupId>org.modelmapper</groupId>
      <artifactId>modelmapper</artifactId>
      <version>1.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java mysql spring mysql-workbench spring-boot

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

如何使用 Angular 2 / 4 禁用表单内的输入操作?

我正在更新一个用 Angular 4 制作的项目。该网站由多个表单组成,其中包括输入字段。当用户按下“输入”时,表单就会被提交。我想阻止这种情况发生。我怎样才能做到这一点?

我可以在引号内添加一些内容来阻止提交操作的发生:(keydown.enter)=""

表单.组件.html

<div class="d-flex justify-content-center hm-row">
  <form class="hm-form" [formGroup]="crossingForm">
    <div class="form-group">
      <label for="dynamicThresholdTime">{{ 'CROSSING.DYNAMIC_THRESHOLD_TIME' | translate}}</label>
      <input type="text" class="form-control" id="dynamicThresholdTime" placeholder="" formControlName="dynamicThresholdTime">
     </div>
     <...more code...>
   </form>
</div>
Run Code Online (Sandbox Code Playgroud)

html angular2-forms angular

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