Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在这种情况下,如何使用ng if或其他表达式更改文本?_Javascript_Angularjs_Angularjs Ng Repeat_Angularjs Ng If - Fatal编程技术网

Javascript 在这种情况下,如何使用ng if或其他表达式更改文本?

Javascript 在这种情况下,如何使用ng if或其他表达式更改文本?,javascript,angularjs,angularjs-ng-repeat,angularjs-ng-if,Javascript,Angularjs,Angularjs Ng Repeat,Angularjs Ng If,我正在尝试根据标记的方向值更改标题标记中的文本: <li ng-repeat="t in tags"> <div class="tag" ng-class="{'green-up': t.direction == 'positive', 'red-down': t.direction == 'negative', '' : t.direction == 'st

我正在尝试根据
标记的
方向
值更改标题标记中的文本:

<li ng-repeat="t in tags">
    <div class="tag"
         ng-class="{'green-up': t.direction == 'positive',
                    'red-down': t.direction == 'negative',
                    ''        : t.direction == 'stagnant'}"
                    title="Percentage increase"
                    ng-if="">{{t.name}}</div>
</li>
  • {{t.name}}
  • 方向为
    停滞
    ,应对应于
    title=“百分比增加”
    title=“百分比减少”
    或仅
    title=“百分比”


    在这种情况下,最好使用哪种角度语法?

    为什么不将标记设置设置为对象

    $scope.tagInfo = {
        positive:{ class:"green-up", title:"Percentage increase" },
        negative:{ class:"red-down", title:"Percentage decrease" }
    }
    
    然后在你的
    ng repeat中调用它

    <div class="tag"
         ng-class="tagInfo[t.direction].class"
         title="{{tagInfo[t.direction].title}}">{{t.name}}</div>
    


    不过,我真的不明白这么做有什么意义。它所做的一切就是让你的代码更加混乱。

    我会考虑制作一个哈希表,并使用
    title={{{t.hashes[t.direction]}
    但这并不完全是“角度”的,是这样做的,只是不想在模型中添加更多内容。。。性能(100个标签)。我想标记中的某种条件可能需要更少?我会再等一会儿,但如果没有其他问题,我会检查这个,然后将我的标题设置为just
    percentage
    我看不出有理由不使用可映射对象。你有没有试过,并注意到一个性能的打击?有比省吃俭用“正确”的方法更好的方法来提高性能
    ng如果
    不起作用,它所做的就是从DOM中添加或删除整个元素。如果希望在标题中包含条件子句,则仍然需要调用范围中某个地方可访问的方法。更新答案。
    $scope.getTitle = function(direction) {
        if (direction==="positive") {
            return "Increase";
        } else if (direction==="negative") {
            return "Decrease";
        }
    };