小编Ale*_*ski的帖子

Webpack和Express - 严重依赖关系警告

我有以下内容webpack.config.ts:

var webpack = require( 'webpack' );
var path = require( 'path' );

module.exports = {

  entry: [
    './api/bin/www.ts'
  ],
  output: {
    path: path.resolve( __dirname, './dist/api' ),
    filename: 'index.js'
  },
  module: {
    loaders: [
      { test: /\.ts$/, loader: 'awesome-typescript-loader' },
      { test: /\.json$/, loader: 'json-loader' }
    ]
  },
  resolve: {
    extensions: [ '', '.js', '.ts' ]
  },
  target: 'node',
  node: {
    console: true,
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }
};
Run Code Online (Sandbox Code Playgroud)

当我运行webpack时,我得到一个关于依赖的警告:

WARNING in ./~/express/lib/view.js
Critical dependencies:
78:29-56 …
Run Code Online (Sandbox Code Playgroud)

express webpack

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

这是"延期反模式"吗?

我发现很难理解"延迟反模式".我认为我原则上理解它,但我没有看到一个超级简单的例子,一个服务,一个不同的承诺和一个反模式,所以我想我会尝试自己做但看到我不是超级了解它我先得到一些澄清.

我在工厂(SomeFactory)中有以下内容:

//url = 'data.json';

return {
    getData: function(){
        var deferred = $q.defer();

        $http.get(destinationFactory.url)
            .then(function (response) {

                if (typeof response.data === 'object') {
                    deferred.resolve(response.data);
                } else {
                    return deferred.reject(response.data);
                }
            })

            .catch(function (error) {
            deferred.reject(error);
        });

        return deferred.promise;
    }
Run Code Online (Sandbox Code Playgroud)

我检查它的对象的原因只是在上面添加一个简单的验证层 $http.get()

以下,在我的指令中:

this.var = SomeFactory.getData()
    .then(function(response) {
        //some variable = response;
    })
    .catch(function(response) {
        //Do error handling here
});
Run Code Online (Sandbox Code Playgroud)

现在我的理解是,这是一个反模式.因为原始的延期承诺会捕获错误并简单地吞下它.它不会返回错误,因此当调用此"getData"方法时,我已经执行了另一个捕获错误的捕获.

如果这不是反模式,那么有人可以解释为什么两者都要求各种"回调"吗?当我第一次开始写这个工厂/指令时,我预计不得不在某个地方做一个默认的承诺,但我没有预料到必须.catch()在两边(也就是我有点想我可以让工厂返回响应或错误,如果我做了一个SomeFactory.getData()

angularjs angularjs-directive angularjs-service angular-promise

17
推荐指数
2
解决办法
2826
查看次数

获取当前节点的值

我对术语并不是很熟悉,所以我甚至不确定问题的标题是否准确,但我会尽力解释.

我有以下XML示例.

<countries>
  <country name="Afghanistan" population="22664136" area="647500">
    <language percentage="11">Turkic</language>
    <language percentage="35">Pashtu</language>
    <language percentage="50">Afghan Persian</language>
  </country>
</countries>
Run Code Online (Sandbox Code Playgroud)

我将XPath用于语言节点(/ countries/country /,然后是for-each for languages).

<language percentage="11">Turkic</language>
Run Code Online (Sandbox Code Playgroud)

使用XSLT如何在上面的例子"Turkic"中输出值.我想不出另一种表达问题的方法,但它就像我在节点,并且不知道获取此节点的值的语法.

提前致谢

xml xslt xpath

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

用于AngularJS的Karma/Jasmine中的模块依赖性

我正在尝试在Karma/Jasmine中为我的项目中的特定模块编写一些单元测试destination-filters.

模块清除:

angular.module('destination-filter', ['ngSanitize']);
Run Code Online (Sandbox Code Playgroud)

我的测试失败,除非我ngSanitize作为依赖项删除.据我所知,这是因为当模块被实例化时,它会尝试并引入该依赖项,但因为在我的spec.js文件中我没有声明该模块失败.

规格文件:

describe('Destination Filter Controller', function () {

  // Set the variables
  var $controller;
  var mockNgSanitize;

  beforeEach(module('destination-filter'));

  beforeEach(function() {
      module(function($provide) {
          $provide.value('ngSanitize', mockNgSanitize);
      });
  });

  beforeEach(inject(function (_$controller_) {
      $controller = _$controller_('DestinationFilterController');
  }));

  it('should expect the controller to not be null', function() {
      // Check the controller is set
      expect($controller).not.toBeNull();
  });

});
Run Code Online (Sandbox Code Playgroud)

以前,在模拟服务或函数时,该$provide方法已证明非常有用,但我不确定我在这里使用它是否正确.我假设$provide以这种方式使用不能模拟整个模块而是服务?

为了澄清,如果我...['ngSantize'])...从模块减速中删除了测试,则测试会正确实例化.我收到的错误留在了Error: [$injector:modulerr] destination-filter

unit-testing mocking angularjs karma-jasmine

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

Angular 2 - ngIf - 不是div的已知属性

所以我显然对ng2很新,就像现在很多人一样.随着第一个版本的发布,我一直在学习.我开始尝试一些更"ng2"的思维方式了.

然而,一件简单的事情ngIf我无法开始工作.

这是我的看法:

<div *ngIf="testVariable" class="checkbox">
    <label>
        <input type="checkbox" formControlName="rememberMe" value="remember-me"> Remember me
    </label>
</div>
Run Code Online (Sandbox Code Playgroud)

在我的component.ts中:

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';

...

ngOnInit() {
    this.loginForm = this._fb.group({
    username: ['', [<any>Validators.required]],
    password: ['', [<any>Validators.required]],
    rememberMe: []
  });

  this.testVariable = false;
}
Run Code Online (Sandbox Code Playgroud)

我是否需要额外输入一些东西?我已经看过pre-release ng2示例导入,CORE_COMPONENTS但我找不到最近的例子.

我的模块声明:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

import { LoginComponent …
Run Code Online (Sandbox Code Playgroud)

angular

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