【发布时间】:2018-01-02 18:41:06
【问题描述】:
我正在尝试从 here 实现 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;
}
【问题讨论】:
标签: ionic2 angular2-directives