这是我的 Angular 2 组件:
@Component({
selector: '[my-component]',
template:`<ng-content></ng-content>`
})
export class MyComponentClass {
@Input() myComponent: string;
...
这允许我在 Angular 2 应用程序中使用它作为任何 html 标签上的指令,例如:
<div [myComponent]="'my text string'"></div>
<span [myComponent]="'my text string'"></span>
但是当在 angularJs 应用程序中使用相同的组件降级时:
angular.module('myApp')
.directive('myComponent', downgradeComponent({component: MyComponentClass , inputs: ['myComponent']}) as angular.IDirectiveFactory);
现在这行不通了:
<div [myComponent]="'my text string'"></div> // or
<div [my-component]="'my text string'"></div>
仅当我将它用作类似组件时
<my-component [my-component]="'some text'"></my-component>
我做错了什么? 我不希望它被用作新的 html 标签,而是作为可以添加到任何 html 元素(指令)的指令。
最佳答案
我遇到了同样的问题并在以下位置找到了一个词:https://github.com/angular/angular/issues/16695#issuecomment-336456199
关于angular - 从 angular 2 到 angularJS 的降级指令组件没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43738698/