小编Nil*_*iya的帖子

检查字符串是不是NULL还是EMPTY

在下面的代码中,我需要检查版本字符串是否为空,然后将其值附加到请求变量.

if ([string]::IsNullOrEmpty($version))
{
    $request += "/" + $version
}
Run Code Online (Sandbox Code Playgroud)

如果有条件,如何检查?

powershell

36
推荐指数
4
解决办法
14万
查看次数

Angular 2+ window.onfocus和windows.onblur

因此,我需要在Angular 2或4中管理我的应用程序的浏览器选项卡是否关注.有没有办法使用window.onfocuswindow.onblur

非常感谢

javascript typescript angular

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

sinon.stub()vs sinon.sandbox.stub()?

在我们的前端单元测试中使用sinonsinon-qunit,我很难理解这些方法的不同之处.我们正在使用sinon.sandbox.stub()(字面意思是功能,我们不创建沙箱),这些存根显然在每次测试后自动恢复.我只是在文档中的任何地方都看不到这一点.

我不认为这种方法存在,我认为你需要使用显式创建沙箱sinon.sandbox.create().在那个沙箱对象上你会调用存根函数i.e. mySandbox.stub(),而不是"sinon.sandbox.stub()".

谁能帮我理解?

javascript unit-testing qunit sinon

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

Angular 4-Nginx / Refresh显示不良页面

我在使用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错误的消息,似乎我需要在某个地方添加重写。感谢帮助。

nginx angular

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

日期格式更改角度2

我需要更改我的日期格式,问题是我不能使用moment.js,我只需要将日期从yyyy-mm-dd转换为dd-mm-yyyy.我使用角度v 2.4.0.

date date-formatting angular

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

如何在角度4中实现strictNullChecks

我试图strictNullChecks在角度4应用程序中实现.

我刚才说 "strictNullChecks": truetsconfig.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中实现?

typescript angular strictnullchecks

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

使用 Pikaday 设置默认时间

我正在使用 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 分叉过一个项目,我不确定从哪里开始。

javascript

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

输入填充动态时,AngularJS表单验证失败

我有以下表格:
在此输入图像描述
如果我点击星号,输入将自动填充所点击的星号.(单击第3颗星,输入将填充数字'3',如下图所示)

在此输入图像描述
明星的输入是ng-required="true".

<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>&nbsp;{{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

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

Angular 1.5将带参数的函数传递给组件?

我有一个像下面这样的会话服务,有两种方法代表两种验证方式:

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)

javascript angularjs

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

Angular - Http在没有异步管道的情况下工作

我只需要获得单项,所以我在模板中使用了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

asynchronous observable angular

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

在LINQ中使用个人方法

我想知道是否可以使用我在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)方法,并且此方法无法转换为存储表达式.

c# linq

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