小编all*_*kim的帖子

webpack TS2304找不到名称'Map','Set','Promise'

我有以下webpack.config.js

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

module.exports = {
  entry: {
    'ng2-auto-complete': path.join(__dirname, 'src', 'index.ts')
  },
  resolve: {
    extensions: ['', '.ts', '.js', '.json', '.css', '.html']
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: "[name].umd.js",
    library: ["[name]"],
    libraryTarget: "umd"
  },
  externals: [
    /^rxjs\//,    //.... any other way? rx.umd.min.js does work?
    /^@angular\//
  ],
  devtool: 'source-map',
  module: {
    loaders: [
      { // Support for .ts files.
        test: /\.ts$/,
        loaders: ['ts', 'angular2-template-loader'],
        exclude: [/test/, /node_modules\/(?!(ng2-.+))/]
      }
    ]
  }
};
Run Code Online (Sandbox Code Playgroud)

以及tsconfig.json

{
  "compilerOptions": …
Run Code Online (Sandbox Code Playgroud)

typescript webpack

66
推荐指数
6
解决办法
7万
查看次数

angular2测试,我如何模拟子组件

如何在茉莉花测试中模拟子组件?

我有MyComponent,使用MyNavbarComponentMyToolbarComponent

import {Component} from 'angular2/core';
import {MyNavbarComponent} from './my-navbar.component';
import {MyToolbarComponent} from './my-toolbar.component';

@Component({
  selector: 'my-app',
  template: `
    <my-toolbar></my-toolbar>
    {{foo}}
    <my-navbar></my-navbar>
  `,
  directives: [MyNavbarComponent, MyToolbarComponent]
})
export class MyComponent {}
Run Code Online (Sandbox Code Playgroud)

当我测试这个组件时,我不想加载和测试这两个子组件; MyNavbarComponent,MyToolbarComponent,所以我想模仿它.

我知道如何使用服务进行模拟provide(MyService, useClass(...)),但我不知道如何模拟指令; 组件;

  beforeEach(() => {
    setBaseTestProviders(
      TEST_BROWSER_PLATFORM_PROVIDERS,
      TEST_BROWSER_APPLICATION_PROVIDERS
    );

    //TODO: want to mock unnecessary directives for this component test
    // which are MyNavbarComponent and MyToolbarComponent
  })

  it('should bind to {{foo}}', injectAsync([TestComponentBuilder], (tcb) => {
    return tcb.createAsync(MyComponent).then((fixture) => {
      let …
Run Code Online (Sandbox Code Playgroud)

testing components unit-testing jasmine angular

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

angularjs路由单元测试

正如我们在http://docs.angularjs.org/tutorial/step_07中看到的,

angular.module('phonecat', []).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider.
      when('/phones', {templateUrl: 'partials/phone-list.html',   controller: PhoneListCtrl}).
      when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
      otherwise({redirectTo: '/phones'});
}]);
Run Code Online (Sandbox Code Playgroud)

建议使用e2e测试进行路由测试,

  it('should redirect index.html to index.html#/phones', function() {
    browser().navigateTo('../../app/index.html');
    expect(browser().location().url()).toBe('/phones');
  });
Run Code Online (Sandbox Code Playgroud)

但是,我认为'$ routeProvider'配置是使用单个函数,函数($ routeProvider)完成的,我们应该能够在不涉及浏览器的情况下进行单元测试,因为我认为路由功能不需要浏览器DOM.

例如,
当url是/ foo时,templateUrl必须是/partials/foo.html,
当url是/ bar时,controller是FooCtrl ,templateUrl必须是/partials/bar.html,控制器是BarCtrl

它是一个简单的IMO函数,它也应该在一个简单的测试,单元测试中进行测试.

我用谷歌搜索并搜索了这个$ routeProvider单元测试,但还没有运气.

我想我可以从这里借一些代码,但还不能实现,https://github.com/angular/angular.js/blob/master/test/ng/routeSpec.js.

unit-testing jasmine angularjs angularjs-routing

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

打印功能的结尾逗号是什么?

此代码来自http://docs.python.org/2/tutorial/errors.html#predefined-clean-up-actions

with open("myfile.txt") as f:
    for line in f:
        print line,
Run Code Online (Sandbox Code Playgroud)

我不明白的是,打印命令结束时的情况.

我还检查了doc,http://docs.python.org/2/library/functions.html#print.

不够了解,这是一个错误吗?(似乎不是.它来自官方教程).

我来自ruby/javascript,这对我来说很不寻常.

python

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

angularjs $ watch旧值和新值是一样的

我的目的是在范围内观察模型,并找出旧值和新值之间的差异.

但是,我发现以下代码中的旧值和新值都是相同的.

app.controller('MyCtrl', function($scope, $timeout){
  $scope.markers = {};
  $scope.$watchCollection('markers', function(newValue, oldValue){
    console.log('being watched oldValue:', oldValue, 'newValue:', newValue);
  });
  $timeout( function() {
    $scope.markers.foo = 1;
  }, 500);
  $timeout( function() {
    $scope.markers.bar = 2;
  }, 500);
});
Run Code Online (Sandbox Code Playgroud)

输出:

being watched oldValue: Object {} newValue: Object {} script.js:6
being watched oldValue: Object {foo: 1} newValue: Object {foo: 1} script.js:6
being watched oldValue: Object {foo: 1, bar: 2} newValue: Object {foo: 1, bar: 2} 
Run Code Online (Sandbox Code Playgroud)

为什么它们是相同的,如果它是故意的,为什么呢?

这是代码,http://plnkr.co/edit/rfMCF4x6CmVVT957DPSS?p=preview

angularjs

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

ActiveRecord :: Relation,有什么方法可以删除现有的限制和偏移?

假设我有一个User模型

paged_users = User.scoped.limit(2).offset(3)
Run Code Online (Sandbox Code Playgroud)

有没有一种方法,使paged_user已经User.scoped通过去除限制和偏移?IE:

all_user = paged_users.remove_limit.remove_offset
Run Code Online (Sandbox Code Playgroud)

activerecord ruby-on-rails

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

使用erl -noshell从控制台运行eunit测试

我想从控制台运行以下eunit test命令

eunit:test([test_module, [verbose]).
Run Code Online (Sandbox Code Playgroud)

我试过这个,但似乎没有工作erl -noshell -pa ./ebin -s eunit test test_module verbose -init stop

~/uid_server$erl -noshell -pa ./ebin -s eunit test test_module verbose -init stop
undefined
*** test module not found ***
::test_module

=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
Run Code Online (Sandbox Code Playgroud)

你知道如何从控制台正确传递一个简单的参数吗?

erlang

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

angularjs指令无法获取以"-start"结尾的属性

我想on-drag-start在AngularJS指令中使用它作为属性,调用ngDraggable.
但是,似乎不可能拥有该属性.

以下代码是纯javascript,我可以on-drag-start作为属性获取.我想我可以获得任何属性,无论属性名称如何.

<h1 id="tag1" on-drag-start="START" on-drag="DRAG" on-drag-end="END" >Hello Plunker!</h1>
Run Code Online (Sandbox Code Playgroud)

纯javasctipt DEMO中的属性:http://plnkr.co/edit/6iODSnf56KtwPFpoC7ck?p = preview

但是,在AngularjS的以下代码中,我无法onDragStart作为属性获取,但可以将其onDragBegin作为属性获取.

<h1 id="tag1" ng-draggable  on-drag="DRAG" on-drag-end="END"
  on-drag-start="START" on-drag-begin="BEGIN">Hello Plunker!</h1>
Run Code Online (Sandbox Code Playgroud)

AngularJS指令中的属性DEMO:http://plnkr.co/edit/RxABAHHlxQJSSZz91CYW?p = preview

当然,我可以改变我的属性名称on-drag-starton-drag-begin,但是我很好奇.

我的问题是;

  1. 为什么我不能on-drag-start用作属性名称?
  2. 这背后的原因是什么?
  3. 并且,属性名称是否有任何一般规则?

注意:我觉得我的问题格式不正确.欢迎重写.

angularjs angularjs-directive

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

Angular ui-router将值解析为字符串

使用ui-router,我在状态函数中添加所有解析逻辑,如下所示;

    //my-ctrl.js
    var MyCtrl = function($scope, customers) {
      $scope.customers = customers;
    }

    //routing.js
    $stateProvider.state('customers.show', {
      url: '/customers/:id',
      template: template,
      controller: 'MyCtrl',
      resolve: {   // <-- I feel this must define as like controller
        customers: function(Customer, $stateParams) {
          return Customer.get($stateParams.id);
        }
      }
    });
Run Code Online (Sandbox Code Playgroud)

但IMO,resolve对象必须属于控制器,如果在控制器文件中定义它,则易于读取和维护.

    //my-ctrl.js
    var MyCtrl = function($scope, customers) {
      $scope.customers = customers;
    }
    MyCtrl.resolve = {
      customers: function(Customer, $stateParams) {
        return Customer.get($stateParams.id);
      };
    };

    //routing.js
    $stateProvider.state('customers.show', {
      url: '/customers/:id',
      template: template,
      controller: 'MyCtrl',
      resolve: 'MyCtrl.resolve'   //<--- Error: …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-routing angularjs-controller angular-ui-router

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

angular2从指令访问ngModel变量

我正在尝试构建如下所示的日期时间选择器指令.
<input [(ngModel)]="date1" datetime-picker date-only />

并被date1指定为日期,例如,new Date()

当我在html中显示它时,input元素中的文本如下所示
Thu Jan 01 2015 00:00:00 GMT-0500

我希望显示如下所示
2015-01-01 00:00:00

我想使用DatePipe格式化日期WITHIN,而不是显示默认的toString()函数的结果.

我的问题是; "在一个指令中,我如何访问ngModel变量?",例如date1,这样我就可以添加toString()方法.

如果我的方法不对,请告诉我.

directive angular2-ngmodel angular

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