如何在ng模型中创建三元运算符? Angular.js

时间:2016-12-29 15:55:51

标签: angularjs

当我添加一个新的动态文本字段时,我将其添加为“0”,默认情况下,我想做一些事情,如果值为“0”,则将其替换为“”。

     $scope.add=function(){
          $scope.aAnimals.push({ "animal": "0"})
     }

    <div ng-repeat='item in aAnimals'>
     THIS IS MY IDEA in ng-model but i have an error..<!--item.animal=='0'?'':item.animal-->  
    <input type='text' ng-model=item.animal class='animal' />
    </div>

http://plnkr.co/edit/ukTl0ho5gPpOE6jMLq11?p=preview

1 个答案:

答案 0 :(得分:1)

为此创建过滤器:

{{item.animal|blankZero}}

在视图中使用它:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    let viewcontroller = segue.destination as! ManageUserSettingsTableViewController
    // Pass the selected object to the new view controller.

    //let object = self.writeSelectedUID as? String
    // let object = self.writeSelectedUID as! String!

    if(segue.identifier == "editUser") {
             if let object = self.writeSelectedUID {
                   viewcontroller.detailItem = object as AnyObject?
             }
    }
}