Angular2-text-ticker-directive在Ionic 2项目中不起作用



我正在尝试从这里实现Angular2-text-ticker-directiv,但它不起作用。我得到了div,div 是空的,没有滚动文本。

为了进行测试,我将示例代码添加到我的项目中进行测试。

<ion-avatar item-left>
<span class="story-username">{{getUsername()}}</span>
<ion-icon name="icon-mapporia-edit" role="img" class="icon icon-ios ion-ios-icon-mapporia-edit story-edit" aria-label="icon mapporia-edit" ng-reflect-name="icon-mapporia-edit"></ion-icon>
<p class="story-location">{{story.location}}</p>
<div class="tickerContainer myStyles">
<div ticker [trigger]="'auto'" [text]="'A statically-typed, long string'" [speed]="50" [padding-right]="40" [size]="20"></div>
</div>
<p class="story-time">{{calculatePostedTime()}}</p>
<rating [(ngModel)]="story.ratingAvarege" readOnly="true" max="5" emptyStarIconName="star-outline" halfStarIconName="star-half" starIconName="star" nullable="false"></rating>
<p class="story-subject">{{story.subject}}</p>
</ion-avatar>
<li class="thumnail-list" *ngFor="let image of story.images">
<img-loader [src]="image" [spinner]="true" class="thumnails" alt="Story Image" id="story-image">
</img-loader>
</li>

我在调用自定义指令之前添加了<div id="ghost"></div>(显示(:

<div class="profileDetails">
<story-summary *ngFor="let story of myStories" [story]="story" (click)="readStory(story)" class="story"></story-summary>   
</div>

我还包含了给定的 css:

.tickerContainer {
overflow-x: hidden;
overflow-y: scroll;
white-space: nowrap;
}
#ghost {
display: inline-block;
height: 0;
position: absolute;
}
.myStyles {
background: #eee;
color: blue;
border: 1px solid #ddd;
max-width: 200px;
cursor: pointer;
}

如果有人有经验的人可以帮助我解决这个问题。 嘟

我发现了一个错误。 请按给定的方式更正以下方法:

getTextWidth(): number {
let t = this.r.createElement( document.getElementById('ghost'), 'div' );
// this.r.setText( t, this.text ); // not working, oddly
t.innerHTML = this.text; // quick fix
this.r.setElementStyle( t, 'font-size', this.size + 'px');
let w = t.offsetWidth;
t.innerHTML = '';
return w;
}

我也遇到了和你一样的问题。您提供的链接中的股票代码指令包含一些错误。

老-

createTickerNode( self: any , text: string ): any {
self = this.r.createElement( this.el.nativeElement, 'span' );
this.r.setElementStyle( self, 'padding-right', this.paddingRight + 'px');
this.r.setElementStyle( self, 'font-size', this.size + 'px');
this.r.setText( self, text );
return self;
}

新-

createTickerNode( self: any , text: string ): any {
self = this.r.createElement( this.el.nativeElement, 'span' );
this.r.setElementStyle( self, 'padding-right', this.paddingRight + 'px');
this.r.setElementStyle( self, 'font-size', this.size + 'px');
// this.r.setText( self, text ); // not working, oddly
self.innerHTML = this.text; // quick fix
return self;
}

将股票代码指令中的旧代码替换为新代码。 希望它能帮助解决您的问题。如果是,请将我的答案标记为正确:)

最新更新