我目前正在将我的项目从ES5转换为ES6,但我遇到了MomentJS(version 2.18.1
)的问题.问题是我有一些变量是Moment对象,但是我不能在它们上面调用moment().
一个例子:
import * as moment from "moment";
export class DateThingy {
constructor(private moment) { //What type does this have??
}
public getDate(): moment.Moment {
return this.moment();
}
}
Run Code Online (Sandbox Code Playgroud)
1)如果我设置的类型private moment
来private moment: moment
WebStorm抱怨:" 找不到名称'时刻’ "
2)如果我将类型设置private moment: moment.Moment
为对象已更改,我不能再调用this.moment()
(它现在是一个对象,并且没有函数调用).Webstorm告诉我:" 不能调用一个类型没有呼叫签名的表达式.类型'Moment'没有可以召集的呼叫签名. "
3)我不能再使用MomentStatic,因为它不会被导出.如果我输入private moment: moment.MomentStatic
WebStorm给我:" 命名空间'时刻'没有导出的成员'MomentStatic' "
那么我应该为这个例子使用什么打字?
好的,我有一个Cordova和AngularJS的移动应用程序.对于样式,我使用Less和Bootstrap.
问题
在移动应用程序中,我试图用百分比(%)来调整我的div.但这似乎不起作用.我似乎无法改变以下行为:The divs are as big as the content inside of them
.这个问题听起来很简单,我在这里尝试了很多选项(stackoverflow)以及在网络上.然而,我还没有找到修复它的解决方案,而且它变得非常烦人.
我试过了
添加html, body { height: 100% }
,
添加 html, body, #canvas { height: 100%}
添加 #canvas { min-height: 100% }
添加 html { height: 100% } body { min-height: 100% }
还有很多其他的变化.使用px工作,但我不知道我的移动设备有多大,所以这不是真正的方便..(我也使用bootstrap和一些媒体查询样式).
例
当我向div添加元素时,我得到以下行为:
我想删除那个空白空格,但我只能在使用px而不是%时实现.
少例:
html, body {
background: transparent;
height: 100%;
margin: 0;
padding: 0;
}
#canvas …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个可以从HTML模板创建电子邮件模板的函数以及给出的一些信息.为此我使用$compile
Angular 的功能.
我似乎无法解决一个问题.该模板由一个基本模板组成,其中包含无限量的模板ng-include
.当我使用'最佳实践' $timeout
(这里建议)时,当我删除所有的时,它会起作用ng-include
.所以这不是我想要的.
$ timeout示例:
return this.$http.get(templatePath)
.then((response) => {
let template = response.data;
let scope = this.$rootScope.$new();
angular.extend(scope, processScope);
let generatedTemplate = this.$compile(jQuery(template))(scope);
return this.$timeout(() => {
return generatedTemplate[0].innerHTML;
});
})
.catch((exception) => {
this.logger.error(
TemplateParser.getOnderdeel(process),
"Email template creation",
(<Error>exception).message
);
return null;
});
Run Code Online (Sandbox Code Playgroud)
当我开始向ng-include
模板添加's时,此函数开始返回尚未完全编译的模板(workarround是嵌套$timeout
函数).我相信这是因为a的异步性质ng-include
.
工作代码
此代码在完成渲染时返回html模板(现在可以重用函数,请查看此问题的问题).但是这个解决方案是一个很大的问题,因为它使用有角度的私有$$phase
来检查是否有任何进行中$digest
的.所以我想知道是否有其他解决方案?
return this.$http.get(templatePath)
.then((response) => {
let template = response.data;
let …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Angular 6构建一个应用程序,我仍在设置所有内容.但似乎我的应用程序中的依赖注入有问题.
它无法解析任何构造函数参数.他们都导致了Uncaught Error: Can't resolve all parameters for AppComponent: (?).
.即使是自定义服务也会导致相同的错误.
版本 (省略了对此不会产生任何影响的依赖项)
"dependencies": {
"@angular/common": "6.0.5",
"@angular/compiler": "6.0.5",
"@angular/core": "6.0.5",
"@angular/forms": "6.0.5",
"@angular/http": "6.0.5",
"@angular/platform-browser": "6.0.5",
"@angular/platform-browser-dynamic": "6.0.5",
"@angular/router": "6.0.5",
"core-js": "2.5.7",
"reflect-metadata": "0.1.12",
"rxjs": "6.2.1",
"zone.js": "0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "6.0.5",
"@ngtools/webpack": "6.0.8",
"angular2-template-loader": "0.6.2",
"awesome-typescript-loader": "5.1.0",
"typescript": "2.7.2",
"webpack": "4.12.0",
"webpack-cli": "3.0.8",
"webpack-dev-server": "3.1.4",
}
Run Code Online (Sandbox Code Playgroud)
app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { …
Run Code Online (Sandbox Code Playgroud) dependency-injection typescript ngx-translate angular angular6
我想在 an 上设置一些验证<input>
以防止用户输入错误的字符。为此,我正在使用ng-pattern
. 它目前禁止用户输入错误的字符,但我也注意到这不是预期的行为,所以我也计划创建一个指令。
我在用
AngularJS:1.6.1
正则表达式应该匹配什么
以下是正则表达式字符串的要求:
注意:“x”是可变的,可以是 0 到 100 之间的任何数字。
'x' 位置的数字是可变的,因此如果可以创建一个易于更改的字符串,将不胜感激!
我试过的
我在其中尝试了一些正则表达式字符串:
1) ^0*([0-9]\d{1,2})$
--> Does match 01 but not 1
--> Does match 32 where it shouldn't
Run Code Online (Sandbox Code Playgroud)
2) ^[1-9][0-9]?$|^31$
--> Does match 1 but not 01
--> Does match 32 where it shouldn't
Run Code Online (Sandbox Code Playgroud)
为了测试,我使用https://regex101.com/tests。
我在尝试中遗漏了什么?
我正在使用Angular(6.0.7
)构建应用程序,并且尝试使用新的创建服务:
@Injectable({
providedIn: 'root'
})
Run Code Online (Sandbox Code Playgroud)
但是,如何使用接口键入注入?
问题
我有2个服务,Authentication.service和SessionStorage.service。我想将sessionstorage注入到身份验证服务中。可以通过以下方式完成:
constructor(private sessionStorage: SessionStorage) {
}
Run Code Online (Sandbox Code Playgroud)
没问题。但是出于面向对象的目的,我希望interface
在此服务之上(这样我就可以将localstorage服务都实现为sessionstorage服务)。因此,我想用接口键入注入的类是合乎逻辑的,但这不能以与Angular 5及更低版本相同的方式完成。
那么,如何通过界面在该全局服务中键入注入?
我试过了
Angular服务类型描述了InjectableProvider
,但是与的兄弟姐妹的任何参数都不匹配InjectableProvider
,因此这会产生编译器(和tslint)错误。
@Injectable({
providedIn: 'root'
}, {provide: IStorageService, useClass: SessionStorage})
Run Code Online (Sandbox Code Playgroud) 因此,在我修复了"415 media media not supported"错误(不支持415媒体)后,我遇到了一个新问题.我RequestBody
总是空着的.当我通过Chrome PostMan发送请求时,我总是得到一个只有空值的序列化实体.我使用Spring (4.2.3.RELEASE)
,Jackson-databind (2.6.3)
并jackson-core (2.6.3)
在我的项目.我在我的项目中使用基于注释的配置(@EnableWebMvc
以使spring自动发现 HTTPMessageConverters
).
其他帖子
我知道stackoverflow上的其他帖子,几乎相同的问题.但他们没有给我答案.此外,大多数帖子都是针对较旧的Spring版本(4.0之前版本),所以现在有些东西完全不同了.
类似帖子:
Spring的@RequestBody在POST上提供空字符串
弹簧控制器
在我的春天,@RestController
我有以下代码:
@RequestMapping(value = "/location/update/{id}", method = RequestMethod.PUT)
public UserLocation updateUserLocation(@PathVariable("id") int id, UserLocation user) {
return user;
}
Run Code Online (Sandbox Code Playgroud)
我使用单独的模型类(UserLocation
)进行数据绑定.这是因为这样我可以更好地控制我的API发送和接收的数据.
数据绑定类(UserLocation)
UserLocation类包含3个属性,包含构造函数和所需的getter和setter.(我可以公开这些属性,但我首先要解决这个问题).
public class UserLocation {
private Float latitude;
private Float longitude;
private Date lastActive;
}
Run Code Online (Sandbox Code Playgroud)
JSON正文
通过我的AngularJS Ajax调用($http.PUT
)我使用以下数据调用spring控制器:
{
"latitude": 52.899370,
"longitude": …
Run Code Online (Sandbox Code Playgroud) 我创建了一个 C# 项目 ( C# 7.0
& .net framework 4.7.2
),并添加了一些单元测试 ( NUnit 3.11.0
)。
该代码存储在 Gitlab 存储库中,我可以在本地运行测试和构建。但现在我想通过 Gitlab CI 自动执行此操作。根据这篇stackoverflow 帖子和互联网上的很多文章,您应该在 Windows 计算机上创建自己的运行器。
但其中大多数答案已经很旧了,Gitlab CI 现在可以使用 Docker 镜像。但后来我遇到了我的问题。我应该为这个跑步者使用什么图像?我尝试过microsoft/dotnet-framework和microsoft/dotnet但这些都不起作用。
给出microsoft/dotnet-framework
错误消息:No such image: microsoft/dotnet-framework
并且microsoft/dotnet
图像不包含.net 4.7.2
库,因此它不能用于构建。
Gitlab CI + Docker 镜像 + C# 构建?
是否仍然无法使用用于 C# 构建(控制台应用程序)的 Docker 映像创建 Gitlab CI 运行器?或者我只是在这里做错了什么?
我当前的 .gitlab-ci.yml
image: microsoft/dotnet-framework
stages:
- build
before_script:
- 'dotnet restore'
app-build:
stage: build
script:
- …
Run Code Online (Sandbox Code Playgroud) 我有Cordova和AngularJS的应用程序.
使用Angular,我将一个值发送到我的后端应用程序(Spring REST).我用它的方法是$ http.post.
问题
当我尝试将数据发送到我的服务器时,Spring不会在我的实体中设置值.由于这个原因,我无法保存我的新数据.
角度代码
我的AngularJS代码如下:
httpService.createInBackend = function (url, data, callback, errorCallback) {
http.post(url, data)
.then(function (success) {
callback(success);
}, function (error) {
errorCallback(error.data);
});
};
Run Code Online (Sandbox Code Playgroud)
我使用以下参数:
网址: http://<location>:<port>/<application>/<web_socket_url>
数据:
data: {
{
"incidentTypeId": 5,
"priorityId": 1,
"creationDate": 1449676871234,
"userId": 1,
"latitude": <some valid location>,
"longitude": <some valid location>
}
},
timeout: 4000
}
Run Code Online (Sandbox Code Playgroud)
我使用' data '而不是' params ',因为我想通过正文发送数据.我得到了这个与PUT功能一起使用,与此功能没有多大区别.
我的REST控制器
@RequestMapping(value = "/employee/new", method = RequestMethod.POST)
public NewEmployee createIncident(@RequestBody …
Run Code Online (Sandbox Code Playgroud) 我正在尝试做的事情:
我正在尝试创建一种创建 md 列表的通用方法。该列表将基于其 html 标签内的输入。为了创建这个列表,我正在使用ng-transclude
. 我正在使用的编程语言是TypeScript
. TypeScript 被编译为ES5
.
我使用的版本:
角度:1.5.6
角度咏叹调:1.5.6
角材料:1.0.9
问题
我正在尝试将ng-click
事件添加到md-list-item
. 单击事件绑定到的函数受指令范围的约束。当我尝试运行代码时,该ng-click
元素没有出现在md-list-item
. 从逻辑上讲,单击列表项不会触发任何事件。
我认为ng-click
未在 上设置该元素的原因md-list-item
是因为我收到了 aria 警告。如下:
ARIA: Attribute " aria-label ", required for accessibility, is missing on node:
<button class="md-no-style md-button md-ink-ripple" type="button" ng-transclude="" ng-click="click(item)" aria-label="">
<div class="md-list-item-inner ng-scope"></div>
</button>
Run Code Online (Sandbox Code Playgroud)
在 md-list-item 上添加aria-label="tab-item"
可以修复错误,但 ng-click 元素仍会从 md-list-item 元素中删除。
我的代码
列表.html
<md-list ng-class="'{{listClass}}'">
<md-list-item ng-repeat="item in items" …
Run Code Online (Sandbox Code Playgroud)