我试图limitTo在字符串上运行Angular2上的管道:
{{ item.description | limitTo : 20 }}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
The pipe 'limitTo' could not be found
Run Code Online (Sandbox Code Playgroud)
这是我的 app.module
从'./limit-to.pipe'导入{TruncatePipe};
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
InMemoryWebApiModule.forRoot(InMemoryDataService),
RouterModule.forRoot([
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},
{
path: 'home',
component: GridComponent
},
])
],
declarations: [
AppComponent,
TopNavComponent,
GridComponent,
TruncatePipe
],
providers: [
PinService,
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
我使用管道的网格组件:
import { Component,OnInit } from '@angular/core';
import { Router } from '@angular/router'; …Run Code Online (Sandbox Code Playgroud) 我一直在研究制作一个角度指令,如果它有超过一定数量的字符(例如115),它会缩短段落或div.
我找不到任何对我有用的东西,我已经看过http://dotdotdot.frebsite.nl/,这对一些人有用,但我试图使用角度指令而不是JQuery的.
如果有人可以提供任何帮助,我将非常感激,我基本上是从想法中挖掘出来的.
这是我的视图设置方式:
<div class="Description"
<div class="Content">
<div data-ng-bind-html="item.Description"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我最初只是把它作为jquery就好了,但是不建议只使用jquery和angular
$(function () {
var maxHeight = 115;
var moretext = Localization.Shared.InstitutionProfileStrings.ShowMore();
var lesstext = Localization.Shared.InstitutionProfileStrings.ShowLess();
$('.__Description').each(function () {
var content = $(this).find(".__Content");
var anchor = $(this).find(".morelink");
if ($(content).height() > maxHeight) {
$(this).addClass("less");
$(anchor).html(moretext);
$(anchor).show();
}
else {
$(anchor).hide();
}
});
$(".morelink").click(function (e) {
e.preventDefault();
var parent = this.parentElement;
if ($(parent).hasClass("less")) {
$(parent).removeClass("less");
$(this).html(lesstext);
$(parent).addClass("more");
}
else if ($(parent).hasClass("more")) {
$(parent).removeClass("more");
$(this).html(moretext);
$(parent).addClass("less"); …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
<option ng-repeat="name in names" value="{{names.name}">
{{names.name | limitTo:10 }}
</option>
Run Code Online (Sandbox Code Playgroud)
我该如何添加条件:
if( names.name.length > 10) {
//add ... point after name displayed
}
Run Code Online (Sandbox Code Playgroud)
得到结果 <option value="Alexander Bradley">Alexander ... </option>
有任何想法吗?
我正在使用AngularJS和Ionic,我正在使用ng-bind-html从其他API中提取数据.我想限制字符数量,但在字符后面还有三个点,以显示用户还有更多要阅读的内容...
到目前为止,我有:
<p ng-bind-html="item.excerpt | limitTo: 100"></p>
Run Code Online (Sandbox Code Playgroud)
但这只会限制角色并将其切断.
我想限制"ng-repeat"显示JSON数据时显示的字符数.这个应用程序在RoR框架内使用AngularJS.目前我有以下代码显示每个"item.description",但不限制字符串中的字符数为25.
HTML:
<div ng-controller="MyController">
<ul>
<li ng-repeat="item in artists">
{{item.description | limitTo:25}}
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
控制器:
var myApp = angular.module('myApp', []);
myApp.controller("MyController", function MyController($scope, $http){
$http.get("/assets/data.json").success(function(data){
$scope.artists = data;
});
Run Code Online (Sandbox Code Playgroud)
我还尝试将"limitTo:"选项放在"ng-repeat"中,但这限制了显示的"item.description(s)"的数量,并没有限制字符串/内容.我按照这些说明解决了这个问题:https://docs.angularjs.org/api/ng/filter/limitTo