2016-09-15 8 views
1

を発射ませんここでは、ここでNGクリック任意のイベント

<div ng-app="angularPHP"> 
<div ng-controller="mainpagecntl"> 
    <div id="customer" class="cuscontainer" hidden="hidden"> 
     <div> 
      <h3 class="modal-title" >Add customer</h3> 
      <i class="fa fa-times" id="clo" aria-hidden="true"></i> 
     </div> 
      <table> 
      <tr> 

       <div class="form-group" > 
       <td><label id="label" class="control-label">customer Name:</label> 
       <td><input type="text" class="form-control" ng-model="customer_name" /> 
       </div> 
      </tr> 
      <tr> 
      <div class="form-group"> 
       <td><label id="label" class="control-label">Address:</label></td> 
       <td><input type="text" class="form-control" ng-model="customer_add"/></td> 
      </div> 
      </tr> 
      </table> 
       <div class="madal-footer"> 
        <button class="btn btn-primary" ng-click="custadd()">ADD</button><br /> 

       </div> 
     </div> 
</div> 
</div> 

は私の角度-jsの一部..ですイムは、詳細を入力しようとしているところから、私のHTML部分..です

var app = angular.module('angularPHP', []); 
    app.controller('mainpagecntl', function($http,$scope) 
    { 
     $scope.custadd= function() 
      { 
      data={ 
        cname :$scope.customer_name,        
         cadd: $scope.customer_add, 
        } 
        $http.post("../pos_system/Widgets/addcust.php?add",data).success(function(data) 
        { 
        }); 
        } 
     }); 

が、私はボタンをクリックしても何も起こらなかった。

+0

ng-appディレクティブで角度を調整しましたか? ng-controller指令を使用していますか? – Amygdaloideum

+0

ng-controllerディレクティブを使用しています。@ DanielBornstrand –

+0

データオブジェクトにvarを指定します。クリック機能にconsole.logや警告を付けて確認してください。残りのコードをコメント – vbharath

答えて

0

機能がまったく発射されていないよろしいですこの

<div id="customer" class="cuscontainer" hidden="hidden" ng-controller="myCtrl"> 
+0

すでにng-controllerが追加されています –

0

よう<div id="customer" class="cuscontainer" hidden="hidden">ng-controller="myCtrl"を追加してみてください?それは発砲しているかもしれないが、単にデータを投稿することができない。 console.log何かすぐに確認する関数の中に何か。

var app = angular.module('angularPHP', []); 

app.controller('mainpagecntl', function($http,$scope) { 

    var vm = this; 

    vm.custadd = function() { 

     console.log('test'); 

     var data = { cname :$scope.customer_name, cadd: $scope.customer_add}; 

     $http.post("../pos_system/Widgets/addcust.php?add",data) 
     .success(function(data) { 
     console.log(data); 
     }); 

    } 

} 

次に、あなたのngのクリックは、それが何の違いを作るかどうかを確認し、この

ng-click='vm.custadd()' 

のようになります。

注:以下のコメントで述べたようにあなたのNG-コントローラはまた、

ng-controller="mainpagecntl as vm" 

のようになります。

+0

bharathvはデータオブジェクトのvarを宣言するのを忘れているかもしれません。 – user2085143

+0

それは働いていない.. @ user2085143 –

+0

あなたのコントローラを投稿してください! – user2085143

0

コードの作業デモhttps://plnkr.co/edit/k7yApAavre66KFAiVlOp?p=previewはここにあり、[追加]ボタンをクリックすると完全に機能しました。私は悪い習慣であるので、テーブルからいくつかのdivタグを削除しましたが、Angularはそのディレクティブがそれらに使用されたときにそれらのタグを識別しません。

var app = angular.module('angularPHP', []); 
app.controller('mainpagecntl', function($http, $scope) { 
    $scope.custadd = function() { 
     $scope.data = { 
      cname: $scope.customer_name, 
      cadd: $scope.customer_add, 
     } 
     // $http.post("../pos_system/Widgets/addcust.php?add", data).success(function(data) {}); 
    } 
}); 
関連する問題