2016-10-26 6 views
0

後の角度スクリプトを実行することができますことは、私のhtmlコードです:どのように私はここでのonclickイベント

角度スクリプトで
<div ng-app="myApp" ng-controller="customersCtrl"> 
     <p id="druzyny"></p> 
    </div> 

、その後:

 var app = angular.module('myApp', []); 
     document.getElementById("search1").onclick = app.controller('customersCtrl', function($scope, $http){ 
     var place = document.getElementById("place").value; 
     var sel1 = document.getElementById("sel1").value; 
     var sel2 = document.getElementById("sel2").value; 
     var req = { 
      method: 'post', 
      url: 'findTournament', 
      headers: { 
      'Content-type': 'application/json' 
      }, 
      data: {place: 'test'} 
     }; 

     $http(req).then(function(response){ 
     }); 
     }); 

I`veは、ボタンID = "がsearch1" とiを得ましたその角度を実行したいのは、このボタンをクリックしたときだけです。ページがリロードされても自動的には実行できません。

<div ng-app="myApp" ng-controller="customersCtrl as customers"> 
    <input data-ng-model="customers.place"> 
    <input data-ng-model="customers.sel1"> 
    <input data-ng-model="customers.sel2"> 
    <button data-ng-click="customers.init()"></button> 
</div> 

JS:answears

+0

あなたがボタンをクリックしたときにのみアンギュラ実行したいのはなぜ?ちょっと変わったようです – starcorn

+0

https://docs.angularjs.org/api/ng/directive/ngClick – Bobbyrogers

+0

私はサーバにリクエストする必要がありますが、フィールドのデータを入力してください – willy

答えて

0

HTMLのための おかげ

angular.module('myApp', []); 

angular 
    .module('myApp') 
    .controller('customersCtrl', function($scope, customersService){ 
     var vm = this; 
     vm.init = function(){ 
     customersService.findTournament({place: vm.place, sel1: vm.sel1, sel2: vm.sel2}) 
      .then(function(res){}); 
     }; 

    }); 

angular 
    .module('myApp') 
    .service('customersService', function($http){ 
     return { 
     findTournament: findTournament 
     }; 

     function findTournament(data){ 
     return $http.post('findTournament', data); 
     } 
    }); 
関連する問題