如何使用表达式数据删除链接标题属性上的双引号?

时间:2016-03-01 09:59:41

标签: angularjs

我尝试传递"Tags"的链接标题属性。

标签值现在应该是一个数组我试图删除链接标题属性上的双引号。

当我暂停时,我得到: - ["text", "text 1", "text 2"]

但预期的格式(文本大写情况): - [Text, Text 1, Text 2]

HTML

<div class="" ng-controller="myCrtl">
    <span>Heading Documents</span>
    <ul ng-repeat="list in names">
        <li ng-repeat="lists in list.bookmarks">
            <a href="{{lists.link}}" data-toggle="tooltip" data-placement="right" title="{{lists.tags}}">{{lists.title}}</a>
        </li>
    </ul>
</div>

JS文件:

var app=angular.module('MyApp',[]);

app.controller('myCrtl',["$scope",function($scope){
    $scope.names=[{
        "description": "Testing File",
        "totalCount": 6,
        "bookmarks": [{
                "title": "Google",
                "link": "https://www.google.co.in",
                "tags": [
                    "text", "text 1", "text 2"
                ]
            },

            {
                "title": "Test Construction1",
                "link": "http://google.com",

                "tags": [
                    "content", "content 2", "content 3"
                ]
            },
             {
            "title": "Test Connection",
            "link": "https://www.google.com",
            "tags": [
                "message", "message 1"
            ]
        }
        ]

    }];
}]);

1 个答案:

答案 0 :(得分:1)

您获得["text", "text 1", "text 2"]的原因是因为您正在显示包含字符串的数组;如果你想要一个看起来像[Text, Text 1, Text 2]的字符串,那么你可以通过函数管道输出:

  $scope.change = function(a){
     a = a.map(function(x){
        return x.replace(/^[a-z]/,function(m){
            return  m.toUpperCase()
        });
     });
    return "["+a.join()+"]";
  };

在您的视图中,您只需使用它:

<ul ng-repeat="list in names">                                  
<li ng-repeat="lists in list.bookmarks">
  <a href="{{lists.link}}" data-toggle="tooltip" data-placement="right" title="{{change(lists.tags)}}">{{lists.title}}</a></li>

</ul>

jsbin

你也可以使用角度过滤器来做到这一点,但最后的概念是:过滤数据以获得修改后的输出。