如何在angularjs中的md-list-item中临时添加值?

时间:2017-02-16 12:15:06

标签: javascript html css angularjs html5

我尝试使用素材图标在列表中添加一些项目。这些项目由ng-click="contactDetails.contactModes.push(numbers);"永久添加。

我在卡底部给了2个按钮,即保存并丢弃。但问题是,只要点击了材料图标,就会在列表中添加值。意味着不使用丢弃物。我的目标是在列表中临时添加值,这样当用户点击保存时,只有值被保存,否则将被丢弃。

请建议
我的代码:

<md-list-item ng-show="showContactList" class="md-2-line" ng-repeat="numbers in contactList" ng-click="contactDetails.contactModes.push(numbers);">
    <i ng-show="numbers.type == 'sample'" class="material-icons md-avatar-icon">textsms</i>
    <i ng-show="numbers.type == 'CELL' || numbers.type == 'EXT'" class="material-icons md-avatar-icon">phone</i>
    <img class="pad-right-5 md-avatar dime-30" ng-show="numbers.type == 'PAGER'" src="assets/img/contact-pref/pager.png" width="26" style="width:30px;height:28px;margin-left: 5px;">
    <div class="md-list-item-text" ng-class="{'md-offset': phone.options.offset }">
        <h3>  {{ numbers.type }} </h3>
        <p> {{ numbers.value }} </p>
    </div>
    <i class="material-icons md-avatar-icon add-rm-icon margin-right">add</i>
</md-list-item>

请建议。

1 个答案:

答案 0 :(得分:0)

我在控制器中使用了临时变量

$scope.arrayText = [{
            "type": "sample",
            "value": "test"
        }];  

并在代码中进行了以下更改以添加临时内容并最终使用contactDetails.contactModes = arrayText on ng-click added permanently using save button

<md-list-item ng-show="showContactList" class="md-2-line" ng-repeat="numbers in contactList" >
        <i ng-show="numbers.type == 'TruliaCare'" class="material-icons md-avatar-icon">textsms</i>
        <i ng-show="numbers.type == 'CELL' || numbers.type == 'EXT'" class="material-icons md-avatar-icon">phone</i>
        <img class="pad-right-5 md-avatar dime-30" ng-show="numbers.type == 'PAGER'" src="assets/img/contact-pref/pager.png" width="26" style="width:30px;height:28px;margin-left: 5px;">
        <div class="md-list-item-text" ng-class="{'md-offset': phone.options.offset }">
        <h3>  {{ numbers.type }} </h3>
        <p> {{ numbers.value }} </p>
        </div>
        <i class="material-icons md-avatar-icon add-rm-icon margin-right" ng-click="arrayText.push(numbers);">add</i>
                  </md-list-item>