使用多组合AngularJs进行高级搜索

时间:2015-02-17 13:41:20

标签: javascript angularjs scope

我有三个不同的输入框,如下所示:

名字

<input type="text" name="firstName" ng-model="firstName" / >

姓氏

<input type="text" name="lastName" ng-model="lastName" / >

卷号

<input type="text" name="roll Number" ng-model="rNumber" / >

和搜索按钮,根据输入搜索不同的组合..

<button type="button" ng-click="search()">Search</button>

在控制器中:

 $scope.search=function(){
    if($scope.firstName){      //1st case
    //search operation
      }

 if($scope.lastName){    //2nd case
    //search operation
      }    

 if($scope.lastName && $scope.firstName){    // 3rd case is failing
    //search operation
      }
    }

当我尝试第三种类型的搜索时搜索失败,因为因为定义了$ scope.lastName它执行第二种情况而不是我要执行的第三种情况。如果输入我怎么能运行第三种情况是lastName还是firstName?

0 个答案:

没有答案
相关问题