2017-06-07 18 views
0

私は角のjsと完全に新しいですし、NG-場合ときに関数を呼び出そうとすると、真の 私のコード=>ng-ifがtrueの場合に関数を呼び出す方法は?

ng-repeat="image in post.postImages" ng-if="$index <= 3" ng-init="image.showDeleteIcon= false && hellow()" 

と私のjs =>

<script type="text/javascript"> 
     $scope.hellow = function() 
     { 
      alert('hi'); 
     }; 
</script> 

も=>

を試しています
<span ng-if="$index === 3" ng-init="hellow()"></span> 

問題は何も警告していませんか?誰かが私が間違っていることを教えてもらえますか? 。

+0

ポストのサイズ画像はどうぞ? – hamzox

+0

8 .................. –

+1

'$ scope.hellow'関数を処理するには、角型コントローラを定義する必要があります。 – WorkWe

答えて

0

それはこのようにする必要があり、

ng-repeat="image in post.postImages" ng-if="$index <= 3" ng-init="image.showDeleteIcon= false; hellow()"; 
+0

ng-init = "image.showDeleteIcon = false"; hellow(); "..."の後にあることを意味します.... –

+0

一度ng-initの値が割り当てられると、 – Sajeetharan

+0

は動作しません... –

0

機能hellowをバインドするために、その後controllerangularmodule and ng-app)最初に定義して、それが好き変更: Fiddle

<div ng-repeat="image in post.postImages" ng-if="$index <= 3" ng-init="image.showDeleteIcon=false; hellow();"> 

ワーキング

fiddleとスクリプトタグが追加されました。

+0

は上記と同じではありませんか?alert( 'hi'); – Sajeetharan

+0

が角度jsで表示されます。 };スクリプトタグ内それは動作しませんか? –

+0

@Sajeetharan:Qstn。それは 'image.showDeleteIcon = false && hellow()'と書かれ、あなたの答え(編集前)では 'hellow()'は 'ng-init'の外にありました。 – anoop

関連する問題