簡體   English   中英

ng-show through controller不起作用

[英]ng-show through controller is not working

我有一個包含3個元素的頁面。 第一個搜索欄,第二個搜索結果區域和第三個表單。 因此,這里的用例就像,默認情況下,搜索欄和表單div將顯示和隱藏搜索結果div。 如果我在搜索欄上輸入關鍵字,那么我會獲得客戶數據,因此要隱藏表單欄並顯示搜索欄結果。 在搜索結果中,如果我單擊item(client)中的任何一個,然后隱藏搜索結果並顯示div表格。 然后我想在表單字段中填寫單擊的客戶名稱,我是angularjs的新手,請幫助我。

<ion-view title="Client Details" id="page5" ng-init="isSearch=false;isForm=true;" style="background-color:#F1F8E9;">
<ion-content padding="true" class="has-header">
  <label class="item item-input">
      <i class="icon ion-search placeholder-icon"></i>
      <input type="search" ng-model="str" ng-change="searchByName(str)" placeholder="Search Client">
  </label>
  <ion-list ng-show="{{isSearch}}" id="home-list2">
        <ion-item ng-repeat="client in clientList" id="home-list-item2" ng-click="str=true">{{client.name}}</ion-item>
    </ion-list>
    <form ng-show="{{isForm}}" id="clientDetails-form1" class="list ">
        <label class="item item-input item-floating-label" id="clientDetails-input1">
            <span class="input-label">Name</span>
            <input type="text" placeholder="Name">
        </label>
    </form>
</ion-content>

我的控制器文件是

(function() {
var app = angular.module('clientdetailsctrl', ['clientdetailsservice']);
app.run(function($rootScope, $state, ClientDetails) {

});

app.controller('ClientDetailsCtrl', function($scope, $rootScope, $state, ClientDetails) {
    $scope.searchByName = function(str) {
        $scope.isSearch = true;
        $scope.isForm = false;
        $scope.clientList = [];
        ClientDetails.searchByName($scope, str);
    };
});})();

在這里,我試圖更改isSearch和isForm值的值,但是沒有運氣。

更改:

ng-show="{{isForm}}"

ng-show="isForm"

您不必強制評估ng-show

https://docs.angularjs.org/api/ng/directive/ngShow

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM