小编Win*_*cca的帖子

从一个独立的头上做一个git推

我是一个独立的头,并做了一些改变.我想用git推动这些改成这个独立的头部.我不希望我的更改进入开发分支,当然也不是主分支.我正在与另一个人合作.

示例分支

   develop
   master
   *(HEAD detached at origin/49792_testMocha)
Run Code Online (Sandbox Code Playgroud)

如何在不影响开发或掌握的情况下进入头部?

git git-push

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

具有angularJS组件的组件控制器中$ element和$ attrs的用途1.5

我正在努力提高1.5角度组件的速度.我一直在关注Todd Motto的视频,以获得组件以及angular的文档 https://docs.angularjs.org/guide/component.

在这一点上,组件似乎取代了使用控制器的指令,但在我们的1.5代码中,我们仍然会使用指令进行dom操作.

$ element,$ attrs在组件控制器内的目的是什么?这些似乎可用于操纵.这是文档中关于plunker的链接.我知道他们没有使用$元素,但这是我正在阅读的例子.http://plnkr.co/edit/Ycjh1mb2IUuUAK4arUxe?p=preview

但在像这样的代码......

 angular
  .module('app', [])
  .component('parentComponent', {
    transclude: true,
    template: `
      <div ng-transclude></div>
    `,
    controller: function () {
      this.foo = function () {
        return 'Foo from parent!';
      };
      this.statement = function() {
        return "Little comes from this code";
      }
    }
  })
  .component('childComponent', {
    require: {
      parent: '^parentComponent'
    },
    controller: function () {

      this.$onInit = function () {
        this.state = this.parent.foo();
        this.notice = this.parent.statement();
      };
    },
    template: `
      <div>
        Component! {{ $ctrl.state }} …
Run Code Online (Sandbox Code Playgroud)

dom angularjs angularjs-components

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

$ setPristine()不起作用.

****注意我删除了一些其他功能,以便更快地读取代码.我无法清除表格.当我点击带有取消功能的按钮时.我以为我可以设置默认表单,但这没有什么区别.

<form  name="myForm" novalidate ng-submit="submit()"> 
    <table class="mealCost"> 

        <!-- descriptions -->
        <tr> 
            <td> Base Meal Price: </td>
            <td><input type="number" name="price" ng-model="mealPrice" required></td>
        </tr>
        <!-- waiter puts in the info -->
        <tr> 
            <td> Tax Rate: % </td>
            <td><input type="number" step="0.01" name="tax" ng-model="mealTax" required></td>

        </tr>

        <tr> 
            <td> Tip Percentage: % </td>
            <td><input type="number"  name="tip" step="0.01" ng-model="tipPercent" required></td>

        </tr>

    </table>

    <p class="userResponse"> 
    <input type="submit" value="Submit"> 
    <!-- <input id="cancel" type="submit" value="Cancel" ng-submit="cancel(original)"> -->
    <button ng-click="cancel()">Start Over</button>
    </p>

</form>  
Run Code Online (Sandbox Code Playgroud)

这是我的javascript我试图使用按钮命令将我的表单设置为$ setPristine并点击.我设置默认表单会有所帮助,但提交时没有任何反应

var app = angular.module('myApp',[]).
    controller('costController', …
Run Code Online (Sandbox Code Playgroud)

angularjs

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

VS CODE错误S5057在指定的目录中找不到tsconfig.json文件:'.'

我正在使用我的角度2启动项目获得视觉工作室代码.

我已经设置了我的tsconfig.json ...

    {
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}
Run Code Online (Sandbox Code Playgroud)

我立即遇到了这个错误

  [ts] Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
class AppComponent
Run Code Online (Sandbox Code Playgroud)

我无法确定发生了什么,所以我运行了一个构建并得到了这个错误.

error TS5057: Cannot find a tsconfig.json file at the specified directory: '.'
Run Code Online (Sandbox Code Playgroud)

此错误解释了为什么我收到有关组件装饰器的错误,但我不确定为什么找不到tsconfig.json文件.

我只有一个文件夹,它包含除index.html,package.json和.gitignore之外的所有内容.

json visual-studio-code

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

使用角度cli处理多个应用程序

我感兴趣的是能够使用角度cli来引导多个应用程序.

通过angular-cli wiki,我找到了一个例子 https://github.com/angular/angular-cli/wiki/stories-multiple-apps

我也发现了 https://yakovfain.com/2017/04/06/angular-cli-multiple-apps-in-the-same-project/

我浏览了angular-cli.json文件并运行了

    "apps": [
    {
      "name": "app1",
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.css"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    },
    {
      "name": "app2",
      "root": "src",
      "outDir": "dist2",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main2.ts",
      "polyfills": "polyfills2.ts",
      "test": "test2.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app2",
      "styles": [
        "styles.css" …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular

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

如何在 jasmine 中记录值

茉莉花中有类似console.log的方法吗?如果我想注销我正在嘲笑的 $controller 或服务的值,有没有办法做到这一点?

jasmine console.log

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

在mongoose中更新模式以添加新属性

我正在尝试更新架构以添加新的属性字段.我希望它可以像将属性添加到模式一样简单,并且可以访问更新的字段.

我有一个现有的架构

  let userDrinkSchema = new mongoose.Schema({  new Schema
    creator : { 
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'user'  // name of user file
    },
    caffeine: Number,
    mgFloz: Number,
    name: String,
    size: Number,
    updated_at: {
        type: Date,
        default: Date.now()
    }
});
Run Code Online (Sandbox Code Playgroud)

我需要从这个架构中添加id

const UserSchema = mongoose.Schema({

const User = module.exports = mongoose.model('User', UserSchema);
Run Code Online (Sandbox Code Playgroud)

我不知道如何为每个用户添加此属性.我按照这个例子 处理了Mongoose中的模式更改

架构现在是:

let DrinkSchema = new mongoose.Schema({
    user: { 
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'user',
        required: true,
        default: null
    },
    caffeine: Number,
    mgFloz: Number,
    name: String,
    size: Number,
    imageUrl: String,
    date: …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js mongoose-schema

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

设置ng-htmljs-preprocessor karma预处理器

我正在设置我的Karma配置文件,但我不完全理解存在的一些选项,因为我没有成功测试已经通过ngHtml2JsPreprocessor运行的模板

 $templateCached
Run Code Online (Sandbox Code Playgroud)

在ngHtml2JsPreprocessor中,我可以添加一些涉及路径的键值属性.

 ngHtml2JsPreprocessor: {

      stripPrefix: ".*/Went all the way back to the root of my application/",


     // moduleName: 'templatesCached'// 
    },
Run Code Online (Sandbox Code Playgroud)

我现在注释掉模板,以确保我可以访问每个文件作为模块.我正在加载模块没有错误.我可以在我的开发工具中找到templateCached版本.

beforeEach(module('template')); 
Run Code Online (Sandbox Code Playgroud)

我的Templates文件夹位于我创建的基道之外.

basePath: 'Scripts/',
Run Code Online (Sandbox Code Playgroud)

我在预处理器对象中引用它

  preprocessors: {
    '../Templates/**/*.html' : ['ng-html2js']
},
Run Code Online (Sandbox Code Playgroud)

我的所有模板现在都是js文件和缓存.

我在package.json里面 把文件保存为

save-dev

"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.2.2",
"karma-ng-html2js-preprocessor": "^0.2.1",
Run Code Online (Sandbox Code Playgroud)

我在插件中引用了我的安装.

  plugins: [
    'karma-chrome-launcher',
    'karma-jasmine',
    'karma-sinon',
    'karma-ng-html2js-preprocessor'
],
Run Code Online (Sandbox Code Playgroud)

我已经加载了所有文件

files: [

  //jquery libaries
  // angular libraries
  // Scripts files
  // source app.js
  // tests folder and files
]
Run Code Online (Sandbox Code Playgroud)

我的测试开始于Karma

但是,我的指令只是一个空字符串

  element.html()  
Run Code Online (Sandbox Code Playgroud)

返回""

我有吟游诗人注射设置 …

unit-testing angularjs karma-runner ng-html2js

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

在RxJS中组合两个对象

我正在使用服务中的rxjs和angular 2.我有一些json,我可以通过get请求访问.

   private _campInfoUrl = 'api/campInfo/campInfo.json';
  constructor(private _http: Http) { }

  getAvailableCamps() {  
    return this._http.get(this._campInfoUrl)
      .map((response: Response) => response.json())
Run Code Online (Sandbox Code Playgroud)

此时我掌握了所有数据.但要进入这个对象

      {
       "search": {
       "startDate": "2016-06-07",
       "endDate": "2016-06-10"
      },
       "reservations": [
       {"campsiteId": 1, "startDate": "2016-06-01", "endDate": "2016-06-04"},
       {"campsiteId": 1, "startDate": "2016-06-11", "endDate": "2016-06-13"},
       {"campsiteId": 2, "startDate": "2016-06-08", "endDate": "2016-06-09"}
  ] 
}
Run Code Online (Sandbox Code Playgroud)

这就是我想要做的

.map((response: Response) => response.json()) // <IProduct[]>
  .map((tripDate) => ({
    reservations: tripDate.reservations,
    newRes: tripDate.search // <-- how to add this to every return object
  }))
Run Code Online (Sandbox Code Playgroud)

我正在努力弄清楚的是rxjs如何在预留数组对象内"搜索"这样的方式 …

javascript arrays json rxjs

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

将日期范围添加到NgbInputDatepicker输入字段

我正在使用Angular 5.2和ngbootstrap 1.1。该库具有几个不同的datepicker选项,一个用作组件,另一个用作指令。

我正在使用指令。以下是一个如何使用模板设置ngbootstrap指令的示例的链接。

指令示例

选择两个日期后,弹出框会在输入中添加一个日期。

在最初的方法中,我尝试设定

[(ngModel)]=model 
Run Code Online (Sandbox Code Playgroud)

 this.model = `${this.fromDate} / ${this.toDate}`;
Run Code Online (Sandbox Code Playgroud)

但是,我在设置模型后才意识到这一点。该日期是在ngbootstrap的datepicker模块提供的另一个组件内部检查

private _fromDateStruct(date: NgbDateStruct): NgbDate {
  const ngbDate = date ? new NgbDate(date.year, date.month, date.day) : null;
  return this._calendar.isValid(ngbDate) ? ngbDate : null;
}
Run Code Online (Sandbox Code Playgroud)

链接到组件代码

同样,上面的private方法也使得无法扩展类并覆盖检查

class DateInputDirective extends NgbInputDatepicker 
Run Code Online (Sandbox Code Playgroud)

我更深入地挖掘了一下,希望可以改变服务。 NgbDateAdapter服务返回对象,如果不正确,则返回null。我的字符串日期范围不能超过此范围。

NgBootstrap API

fromModel(date: NgbDateStruct): NgbDateStruct {
  return (date && date.year && date.month && date.day) ? {year: date.year, month: date.month, day: date.day} : null;
Run Code Online (Sandbox Code Playgroud)

}

另外,我利用了angular的useClass并 …

typescript ng-bootstrap angular angular5

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