2016-04-28 62 views
3

在角度1中,您可以使用restrict來確定如何使用您的指令。例如:等效的限制:角度2中的AE

angular.module('foo').directive('fooDirective', [function() { 
    return { 
    restrict: 'AE', 
    /* ... */ 
    } 
}]); 

然後你就可以在你的模板中使用這個無論是作爲一個屬性或元素:

<foo /> 

OR

<div foo /> 

我我一直在閱讀網站,如this one,在Angular2中,select正確的方式來定義您的組件現在如何使用:

@Component({ 
    selector: 'Sample' 
}); 

然後在你的模板:

<Sample /> 

同樣,加括號允許它作爲一個屬性:

@Component({ 
    selector: '[Sample]' 
}); 

模板:

<div Sample /> 

但什麼如果我想讓它同時用作職業bute和作爲一個元素,相當於Angular 1中的restrict: 'AE'

回答

0

restrict: 'AE'AngularJS 2中仍然有效。你所指的是Angular 2 for TypeScript。我在您的問題中看不到TypeScript標記。 Go to the link you have provided,並注意在下拉菜單中選擇了Angular 2 for TypeScript

enter image description here

+0

道歉,是的,我用的是打字稿。 –