小编use*_*061的帖子

Angular 4:路由到路由不起作用

在Angular 4中有一些基本的路由概念,我不明白.

index.html:

<base href="/">
Run Code Online (Sandbox Code Playgroud)

文件结构:

- app
|- app.routings.ts
|- collections
|-- collection.component.ts
|-- collection.component.html
|-- collectioninfo.component.ts
|-- collectioninfo.component.html
|- shared
|-- header.component.html
|-- header.component.ts
Run Code Online (Sandbox Code Playgroud)

我的header.component.html中有一个链接:

<a class="nav-link" [routerLink]="['/collections']">
    Collections
</a>
Run Code Online (Sandbox Code Playgroud)

如果我点击它我登陆localhost:4200 /集合.单击按钮时,将以编程方式更改URL(在collection.component.ts中):

this.router.navigate(['/collections/', collection.name]);
Run Code Online (Sandbox Code Playgroud)

我最终在localhost:4200/collections/name - 一切都很好.现在我以编程方式想要回到/ collections(在collectioninfo.component.ts中):

this.router.navigate(['/collections']);
Run Code Online (Sandbox Code Playgroud)

但这不起作用.该网址没有更改,我收到一条错误消息,指出无法加载参数 - 显然/ collections/name正在再次加载.认为它可能是一个路径问题,但这样的事情也行不通:

this.router.navigate(['../collections']);
Run Code Online (Sandbox Code Playgroud)

附加信息:当我在打开/集合时手动重新加载页面时,我将再次转发到主页,但我认为这是另一个问题,与此行为无关.

app.routing.ts:

const APP_ROUTES: Routes = [
  ...
  { path: 'collections', component: CollectionComponent },
  { path: 'collections/:id', component: CollectionInfo },
];
Run Code Online (Sandbox Code Playgroud)

typescript angular2-routing angular angular4-router

9
推荐指数
2
解决办法
8596
查看次数

如何使用 go-sql (postgres) 模拟 gorm 插入

我将Gorm与 postgresql 驱动程序一起使用。我尝试使用go-sqlmock模拟数据库插入:

type Test struct {
    FirstName string `json:"first_name"`
}

func (db *DB) CreateTest() (*Test, error) {
    test := Test{"c"}
    if result := db.Create(&test); result.Error != nil {
        return nil, result.Error
    }

    return &test, nil
}


func TestCreateUser(t *testing.T) {
    _, mock, _ := sqlmock.NewWithDSN("sqlmock_db_0")

    mockedGorm, _ := gorm.Open("sqlmock", "sqlmock_db_0")
    defer mockedGorm.Close()
    myDB := &DB{mockedGorm}

    mock.ExpectExec("INSERT INTO test").WithArgs("c").WillReturnResult(sqlmock.NewResult(1, 1))
    myDB.Exec("INSERT INTO test(first_name) VALUES (?)", "c")


    if _, err := myDB.CreateTest(); err != nil {
        t.Errorf("error …
Run Code Online (Sandbox Code Playgroud)

testing go go-gorm go-sqlmock

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

如何在AngularJS中实现Disqus计数器?

我正试图在我的角度应用程序中的这个官方教程之后实现一个disqus计数器.但我看不到任何数字,所有显示的都是"第一篇文章",这是span元素中的文本,如果我说得对,应该用计数替换.

1)我在body.html的主体结束标记之前添加了count.js(并使用了我的网站名称,而不是像这里的例子):

<script id="dsq-count-scr" src="//mysite.disqus.com/count.js" async></script>
Run Code Online (Sandbox Code Playgroud)

2)因为我正在使用Angular UI路由器,我想我不应该使用链接计数,而是使用标识符:

<span class="disqus-comment-count" data-disqus-identifier="test">First article</span>
Run Code Online (Sandbox Code Playgroud)

3)标识符也在配置中指定:

 this.page.identifier = 'test';
Run Code Online (Sandbox Code Playgroud)

由于我在配置中指定的语言设置已应用,我相信配置已启动.

有谁知道我在这里做错了什么?

disqus angularjs

5
推荐指数
0
解决办法
169
查看次数

SVG剪辑路径适用于Chrome,但不适用于Firefox或Safari

我正在用D3绘制一个相当复杂的折线图.它使用刷子来缩放数据(使用http://bl.ocks.org/mbostock/1667367作为灵感).

虽然它在Chrome中运行得非常好,但图表行忽略了在Firefox和Safari中使用clip-path指定的边框(请参阅附图),我不知道为什么.

CSS:

clip-path: url(#mainChartClip);
Run Code Online (Sandbox Code Playgroud)

JS:

// Clip = borders the canvas for zoom
svg.append('defs')
   .append('clipPath')
   .attr('id', 'mainChartClip')
   .append('rect')
   .attr('width', width)
   .attr('height', height)
   .attr('transform', 'translate(0,-10)');
Run Code Online (Sandbox Code Playgroud)

这是完整的代码:http://codepen.io/anon/pen/RPzeWr

奇怪的是:codepen实际上适用于Firefox和Safari.这可能与它使用的iframe有关吗?

我已经隔离了图表代码,以便100%确定它不会影响其他一些代码,但是当我在Firefox或Safari中使用codepen之外的代码时它不起作用.在此输入图像描述

javascript css svg d3.js

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

Dygraphs不使用ng-repeat

我是AngularJS的新手并使用dygraph构建仪表板.

试图将dygraphs网站上的示例代码放在ng-repeat-list中,只是为了测试.对于y中的每个x,预期相同的样本图.不幸的是,图表没有绘制,只是轴,控制台没有显示任何错误.

<li ng-repeat="x in y">
    <div id="graph">
        <script>
            new Dygraph(document.getElementById("graph"),
                   [ [1,10,100], [2,20,80], [3,50,60], [4,70,80] ],
                   { labels: [ "x", "A", "B" ] });
        </script>
    </div>
</li>
Run Code Online (Sandbox Code Playgroud)

如果我删除ng-repeat,它可以工作(单图) - 所以dygraphs-code是有效的.当然,像我在这里直接在视图中绘制图形是没有意义的,但我仍然想知道为什么它不起作用.我在这里错过了一些一般性观点吗?

dygraphs angularjs ng-repeat

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

ng-grid悬停时显示按钮

有没有办法在ng-grid中显示行悬停按钮(类似http://jsfiddle.net/andrewboni/fnAwN/light/)?

我经常在范围问题上运行(我认为).

我有一个行模板:

rowTemplate: '<div ng-mouseover="grid.appScope.showButton()" ng-mouseout="grid.appScope.hideButton()">
<div ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ui-grid-cell>
</div>
</div>',
Run Code Online (Sandbox Code Playgroud)

和一个带有按钮的单元格模板:

cellTemplate: '<div class="ui-grid-cell-contents button-cell">
<button ng-click="grid.appScope.removeRow(row)" class="btn btn-danger btn-xs pull-right" ng-show="grid.appScope.button">
delete
</button>
</div>'
Run Code Online (Sandbox Code Playgroud)

但是,当我悬停一行时,按钮不仅会出现在悬停行中,而且会出现在每一行中.

完整代码:http://plnkr.co/edit/UV9R4GbaREmchXKpSjfx?p = preview

任何人都可以帮助我吗?

angularjs ng-grid

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

禁用“预期的空间缩进”错误

运行ng lint会给我很多“预期的空间缩进”错误,原因是我使用制表符而不是空格。我可以使用4个空格而不是制表符,但不能使用2个空格缩进。

我了解到,角度cli团队目前尚无任何计划来更改2个空格的缩进,但是有什么方法可以配置不引起警告的短绒呢?

从linting中排除所有.ts文件对我来说不是一个可行的选择,将“ tslint:disable-next-line:indent”放在此处建议的所有文件中也很烦人。

angular-cli

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

如何在Javascript中将字符串数组转换为特定的树结构

我从后端得到一个文件路径列表,它代表一个文件夹结构,如下所示:

paths = ["path/to/file1.doc", "path/to/file2.doc", "foo/bar.doc]
Run Code Online (Sandbox Code Playgroud)

路径的长度是任意的。为了使用文件树组件(angular2-tree-component),我需要将此数据转换为以下格式

nodes = [
    {
        "name": "path",
        "children": [
            {
                "name": "to",
                "children": [
                    {"name": "file1.doc"},
                    {"name": "file2.doc"}
                ]
            }
        ]
    },
    {
        "name": "foo",
        "children": [
            {"name": "bar.doc"}
        ]
    }
]
Run Code Online (Sandbox Code Playgroud)

认为转换数据的最有效方法是

  1. 先用镜像树结构的文件映射数组,然后映射到
  2. 迭代每个键以完成“子/父”关系。

步骤1:

transformToTree(data) {
    const tree = {};
    function addPathsToTree(paths) {
        let map = tree
        paths.forEach(function(item) {
            map[item] = map[item] || {};
            map = map[item];
        });
    }
    data.forEach(function(path) {
        let pathPart = path.split('/');
        addPathsToTree(pathPart); …
Run Code Online (Sandbox Code Playgroud)

javascript mapping typescript angular

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

Angular2:组件不是任何模块的一部分

我有一个工作的ionic/firebase应用程序,现在想要创建一个具有相同功能的Web应用程序.我从这个模板开始:https: //github.com/ng-lisbon/angular-firebase-seed.它是Angular 4,Firebase 3.9.

现在的问题是我想使用@input将数据从父组件传递给它的子组件.关于这一点,有很多不同的教程和线程,但我没有看到我的代码中出错了.

父HTML:

<app-child [message]="parentMessage"></app-child>
Run Code Online (Sandbox Code Playgroud)

家长TS:

@Component({
    selector: 'app-tester',
    templateUrl: './collections.component.html',
    styles: [],
})
export class CollectionComponent implements OnInit {
    userEmail = '';
    alerts = [];
    collections = [];
    childData: any;

  parentMessage = "message from parent"

@Input() message: any;

    constructor(...) { 
        ...
    }

    ngOnInit() {
    }
}
Run Code Online (Sandbox Code Playgroud)

儿童HTML:

{{message}}
Run Code Online (Sandbox Code Playgroud)

儿童TS:

@Component({
    selector: 'app-child',
    templateUrl: './collectioninfo.component.html',
    styles: []
})
export class CollectionInfo implements OnInit {
    @Input() message: string;

    constructor(...) { 

    ngOnInit() {}
} …
Run Code Online (Sandbox Code Playgroud)

firebase typescript angular

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

Spacy 2.0 Matcher:add()至少需要4个位置参数(给定3个)

我正试图通过我机器上的官方文档工作制作Spacy的 匹配器示例.

from spacy.matcher import Matcher

matcher = Matcher(nlp.vocab) 
pattern = [{'LOWER': "hello"}, {'LOWER': "world"}] 
matcher.add("HelloWorld", None, pattern) 
doc = nlp(u'hello world!') 
matches = matcher(doc)
Run Code Online (Sandbox Code Playgroud)

不幸的是我遇到以下错误:

TypeError:add()至少需要4个位置参数(给定3个)

相应的源代码可以在这里找到,重要的部分是

def add(self, key, on_match, *patterns):
    """Add a match-rule to the matcher. A match-rule consists of: an ID
        key, an on_match callback, and one or more patterns.
Run Code Online (Sandbox Code Playgroud)

Spacy最近已更新到2.0版,我安装了该版本并成功将英文模型链接到它.感觉我在这里遗漏了一些非常明显的东西,但我看不出我做错了什么.

python nlp spacy

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