0

私は表示しようとしています。気候は、ユーザーがアクティブであるか、アクティブではありません。データは、ブール形式のAPIを介して取得されます。つまり、ユーザーが真実であるとか、ユーザーが偽であると言います。データがtrueを返す場合は「アクティブ」を表示し、falseを返す場合は「非アクティブ」を表示します。大幅にアプリケーションを介して再利用され、私は角フィルターをこの作業を行うにしたい。 私は角度とJavaスクリプトの初心者です。以前はフィルタを作成していませんでした。APIから真のfalseを返すための角度フィルタ?

私はeventuatlly

<label>{{ $ctrl.myValu | truefalse}}</label> 

$onInit =() => { 
 
     let self = this; 
 

 
     this.siUser.current().then((userData) => { 
 
      let actingAsTenant = userData.user.apikey; 
 

 
      if (actingAsTenant) { 
 

 
       self.siTenant.current().then((tenant) => { 
 
        self.tenant = tenant; 
 
        
 
        ///starts 
 
        if (self.tenant.active == true) { 
 
         self.tenant.active = 'Active' 
 
        } 
 
        else if (self.tenant.active == false){ 
 
         self.tenant.active = 'Not Active' 
 
        } 
 
        //end 
 
        
 
       }, (err) => { 
 
        self.siAlertDialog.error(err.data.message) 
 
       }) 
 

 
      } 
 
     }, (err) => { 
 
      self.siAlertDialog.error('Error rendering tenant details'); 
 
     }); 
 
    }
<strong>{{$ctrl.tenant.active}}</strong>

+0

私は角度フィルタを作成したいので、その再利用可能な私のコードは、上記の働いています。だから私は本当か偽のためのフィルタを作成したい、このような最終的に見える

答えて

1
For this you need to create filter. Try to with the given code 

<!DOCTYPE html> 
    <html lang="en"> 
    <head> 

     <title>Ristorante Con Fusion: Menu</title> 
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
    </head> 
    <body> 

     <div ng-app="myapp" ng-controller="userController" > 
     {{ myValu | truefalse }} 

     <script> 
    var app = angular.module('myapp', []); 

    app.filter('truefalse', function(){ 
     return function(text){ 
      return text ? "Active" : "Not Active"; 
     } 
     }) 
app.controller('userController', function($scope) { 
     $scope.myValu = true; 
}); 
     </script> 
    </body> 
    </html> 
+0

私は角度フィルターを作成したい! 、私のコードが動作しています。 –

+0

このようなもの

+0

このためにはフィルタを作成する必要があります。更新されたコード – Arun

0

あなたは三項演算子を使用することができますどのように使用するか、このelseとHTML でそれを示すならば、これは私です:

をJS

///starts 
     self.tenant.active == true ? 'Active' : 'Not Active'; 
//end 

OR

アンギュラ式で

<strong>{{ $ctrl.tenant.active ? 'Active' : 'Not Active' }}</strong> 
+0

私のコードが動作している、私はangalrフィルタを作成したいので、私はコーディングの代わりにフィルタを使うことができます。このようなもの

+0

フィルタ(フィルタとして機能します)と同じです: '$ scope.truefalse = function(item){ return item? 'アクティブ': 'アクティブではありません'; }; ' ** OR ** ' app.filter( 'truefalse'、機能(){ リターン機能(アイテム){ リターン項目 'アクティブ':? 'がアクティブではありません';} }) ; ' –

関連する問題