在下面的代码中,我需要检查版本字符串是否为空,然后将其值附加到请求变量.
if ([string]::IsNullOrEmpty($version))
{
$request += "/" + $version
}
Run Code Online (Sandbox Code Playgroud)
如果有条件,如何检查?
因此,我需要在Angular 2或4中管理我的应用程序的浏览器选项卡是否关注.有没有办法使用window.onfocus
和window.onblur
?
非常感谢
在我们的前端单元测试中使用sinon和sinon-qunit,我很难理解这些方法的不同之处.我们正在使用sinon.sandbox.stub()
(字面意思是功能,我们不创建沙箱),这些存根显然在每次测试后自动恢复.我只是在文档中的任何地方都看不到这一点.
我不认为这种方法存在,我认为你需要使用显式创建沙箱sinon.sandbox.create()
.在那个沙箱对象上你会调用存根函数i.e. mySandbox.stub()
,而不是"sinon.sandbox.stub()"
.
谁能帮我理解?
我在使用Nginx的远程服务器上部署了Angular 4应用程序,并可以通过以下地址进行访问:http://xx.xx.xx.xx/app
。该应用程序运行良好,可以在我的网站中导航,但是例如刷新一页时http://xx.xx.xx.xx/app/page1
,它将显示nginx的index.html页面。
Nginx的页面位于中/usr/share/nginx/html
,而我的应用程序的页面位于中/var/www/app
。
nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf; */
location /app {
root /var/www;
try_files $uri $uri/ /index.html;
}
}
Run Code Online (Sandbox Code Playgroud)
似乎root /var/www
在刷新期间未考虑该行。
我听到了有关try_files错误的消息,似乎我需要在某个地方添加重写。感谢帮助。
我需要更改我的日期格式,问题是我不能使用moment.js,我只需要将日期从yyyy-mm-dd转换为dd-mm-yyyy.我使用角度v 2.4.0.
我试图strictNullChecks
在角度4应用程序中实现.
我刚才说 "strictNullChecks": true
的tsconfig.json
当我运行应用程序时,ng serve
我得到以下错误.
ERROR in [at-loader] ./node_modules/@angular/forms/src/model.d.ts:244:39
TS2459: Type '{ onlySelf?: boolean | undefined; emitEvent?: boolean |
undefined; } | undefined' has no property 'emitEvent' and no string index signature.
Run Code Online (Sandbox Code Playgroud)
出了什么问题?我们怎样才能
strictNullChecks
在角4中实现?
我正在使用 Pikaday 的 Owen Meads 叉,其中包括时间选择(可以在这里找到)。有没有办法为time-picker
使用 JavaScript设置默认时间?
这是我到目前为止所拥有的:
var timepicker = new Pikaday({
field: document.getElementById('<%= datetimepicker.ClientID %>'),
firstDay: 1,
minDate: new Date(2000, 0, 1),
maxDate: new Date(2100, 12, 31),
yearRange: [2000, 2100],
showTime: true,
autoClose: true,
timeLabel: "Time In Work: ",
use24hour: true,
incrementMinuteBy: 5,
format: 'DD-MMM-YYYY HH:mm',
disableDayFn: function(date) {
return moment().isBefore(moment(date), 'day');
}
});
Run Code Online (Sandbox Code Playgroud)
如果没有,我该如何解决这样的问题?我以前从未从 Github 分叉过一个项目,我不确定从哪里开始。
我有以下表格:
如果我点击星号,输入将自动填充所点击的星号.(单击第3颗星,输入将填充数字'3',如下图所示)
<form name="completeSurveyForm" role="form" novalidate ng-submit="vm.save()">
<ul class="question-list">
<li data-ng-repeat="question in vm.survey.questions | orderBy:'conditionalOrderId' track by question.id ">
<small class="label label-primary pull-right">{{question.questionTypeName}}</small>
<h3>
<b>{{$index +1 }}.</b> {{question.questionBody}}
</h3>
<hr> <!-- Replace here with directives -->
<div data-ng-switch="question.questionType">
<numericrange question="question" data-ng-switch-when="NUMERIC_CHOICE" />
</div>
</li>
</ul>
<button type="submit" ng-disabled="completeSurveyForm.$invalid " class="btn btn-primary">
<span data-translate="fqApp.business.form.submit">Submit</span>
</button>
</form>
Run Code Online (Sandbox Code Playgroud)
而numericrange指令如下所示:
<div class="row">
<div class="col-md-2" ng-if="!completed">
<div>
<span ng-mouseover="showHovered($event)" ng-mouseleave="clearStars($event)" ng-click="selectStar($event)"
data-ng-repeat="sym in range(startNonActive(question), question.maxValue, 1)" class="{{question.symbol}} starred-element" value="{{$index}}">
</span>
<input type="number" name="{{question.id}}" …
Run Code Online (Sandbox Code Playgroud) html javascript angularjs angular-directive angular-validation
我有一个像下面这样的会话服务,有两种方法代表两种验证方式:
angular
.module('myApp')
.service('sessionService', SessionService);
function SessionService() {
var $ctrl = this;
this.logInTypeA = function(username, password, authenticator) {
...
}
this.logInTypeB = function(username, password, authenticator) {
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
我有一个登录表单组件.我想有两个表单实例使用两种不同的登录方法,但在其他方面是相同的:
<log-in-form log-in-method="$ctrl.sessionSerive.logInTypeA"></log-in-form>
<log-in-form log-in-method="$ctrl.sessionSerive.logInTypeB"></log-in-form>
Run Code Online (Sandbox Code Playgroud)
组件的JS看起来像这样:
angular
.module('myApp')
.component('logInForm', {
templateUrl: 'app/components/log-in-form.template.html',
controller: LogInFormController,
bindings: {
logInMethod: '&'
}
});
function LogInFormController() {
var $ctrl = this;
this.username = '';
this.password = '';
this.authenticator = '';
this.logIn = function() {
$ctrl.logInMethod($ctrl.username, $ctrl.password, $ctrl.authenticator);
};
...
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行此命令时出现错误:
TypeError: Cannot use …
Run Code Online (Sandbox Code Playgroud) 我只需要获得单项,所以我在模板中使用了ngIf而不是ngFor.
模板:
<div *ngIf="item | async">
Id {{ item.id }}
Number {{ item.number }}
</div>
Run Code Online (Sandbox Code Playgroud)
服务:
get(id: number): Observable<Response> {
return this.http
.get(`myApi/id`)
.map(response => response.json());
}
Run Code Online (Sandbox Code Playgroud)
零件:
export class DetailItemPage {
private item: Observable<Object>;
ngOnInit(){
this.getItem(6994);
}
getItem(id){
this.itemProvider.get(id).subscribe(
res => {
this.item = res;
console.log(this.item);
});
}
}
Run Code Online (Sandbox Code Playgroud)
在控制台日志中,我正确地看到了对象.
有了这个例子,我得到错误:
InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
Run Code Online (Sandbox Code Playgroud)
但是,如果我删除异步管道,WORKS.我可以看到项目ID和号码.为什么?我做错了什么?
PS:我使用了Angular 4.1.3
我想知道是否可以使用我在LINQ中创建的方法?
var usr = db.Utilisateurs.FirstOrDefault(u => u.Login == user.Login && CreateASCIIMD5Hash(u.password) == user.password);
Run Code Online (Sandbox Code Playgroud)
但我有一个错误:
LINQ to Entities无法识别方法System.String CreateASCIIMD5Hash(System.String)
方法,并且此方法无法转换为存储表达式.
angular ×5
javascript ×5
angularjs ×2
typescript ×2
asynchronous ×1
c# ×1
date ×1
html ×1
linq ×1
nginx ×1
observable ×1
powershell ×1
qunit ×1
sinon ×1
unit-testing ×1