Angular 2中的属性指令@Input别名

时间:2017-04-14 05:30:02

标签: javascript angular

我正在学习Angular 2中的属性指令。在属性指令中使用BOOT_COMPLETED别名时,它不起作用,为什么?

成分

@Input

指令

<p appHighlight = "color">Hightlight Me</p>

2 个答案:

答案 0 :(得分:3)

符号应该是这样的:

<p myHighlight [appHighlight]="color">Hightlight Me</p>

带括号

假设选择器是:

@Directive({
  selector: '[myHighlight]'
})
export class HighlightDirective {

  constructor(private el: ElementRef) { }

  @Input('appHighlight') highlightcolor: string;
  ...

Plunker示例:http://plnkr.co/edit/vqZ4gjHc1KNFro62HlVJ?p=preview

答案 1 :(得分:1)

来自angular docs -

/**
 * Definition for singly-linked list.
 * class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public boolean hasCycle(ListNode head) {
        if(head == null){
            return false;
        }
          ListNode slow = head;
          ListNode fast = head.next;

          while((slow != null) && (fast != null) && (slow.next != null) && (fast.next != null)){
            if(slow == fast){
                return true;
            }
            slow = slow.next;
            fast = fast.next.next;

          }

          return false;
    }
}