代码之家  ›  专栏  ›  技术社区  ›  TimTheEnchanter

在布线时,直到鼠标移动后,才会显示角度2限制值

  •  2
  • TimTheEnchanter  · 技术社区  · 7 年前

    router.navigate 将命名出口导航到新组件。一切都正常,除了我点击图标后,命名路由器出口的新内容直到我移动鼠标才显示。

    以下是指令的相关部分:

    @Directive({
        selector: '[editable]',        
    })
    ...    
    @Output() doEdit = new EventEmitter<string>();
    ...
    private emitEditMessage(){
            console.log("emitting");   <-----just so I can see that the function is called
            this.doEdit.emit(this.targetField);
    }
    

    下面是我在模板中使用指令的地方:

    <span editable (doEdit)="editField($event)">
        {{CurrentPersonInfo}}                              
    </span>
    

    public editField(fldName :string){
        console.log("before nav");
        this.router.navigate([{ outlets: { 'task-pane': 'edit' } }]);
        console.log("after nav");
    }
    

    使现代化 :刚刚注意到:如果任务窗格中的内容只是一个硬编码字符串,那么它会立即显示。但是,如果我将插值绑定添加到任务窗格组件的属性(例如{{Title}}),则任何硬编码文本 绑定立即显示。在我移动鼠标之前,绑定文本和之后的任何硬编码文本都不会显示。

    @Component({
        ...
    })
    export class PersonEditPanelComponent extends BasePanel{    
        constructor(){
            super();
            console.log("panel ctor");
        }
    
        public Title: string = "Edit Person"
    }
    

    This shows immediately.
    
    {{Title}}
    
    This and the "Title" won't show until I move the mouse after clicking the icon
    

    editField 函数(指令发出时调用的同一个函数),然后一切都工作了-所有文本(硬编码和绑定)立即显示。

    谢谢

    1 回复  |  直到 7 年前
        1
  •  1
  •   TimTheEnchanter    7 年前

    解决了的。我采用了不同的方法来连接事件侦听器,并使其全部正常工作。以下是详细信息:

    Renderer2 通过我指令中的构造函数:

    constructor(elem: ElementRef, private renderer: Renderer2, private router: Router)
    {}
    

    this.renderer.listen(this.editIcon, 'click', (evt) => {
        this.doEdit.emit(this.targetField);
    });
    

    哪里 editIcon 是我创建并添加的DOM元素:

        private editIcon = document.createElement('a');
        this.editIcon.innerHTML = '<i class="fa fa-pencil" aria-hidden="true" style="font-size:18px; color:red;"></i>';
        node.appendChild(this.editIcon);