Angular JS发送参数和返回结果

时间:2015-12-02 11:21:26

标签: javascript angularjs

我有问题。我想调用带参数的函数,并在ng-click上通过.md-button获得结果。

在HTML中

<md-button class="md-raised md-primary" ng-click="setreg.register({{reg.email}},{{reg.pass1}},{{reg.pass2}},{{reg.name}});" style="width: 100%">
                Kayıt Ol
            </md-button>
            <div>
                <label>Result :</label>{{setreg.SetRegister}}
            </div>

JS

var app = angular.module("demoApp", ["ngMaterial", "ngMessages"]);

app.controller("SetRegister", ["$http", function ($http) {
var result = this;
var dbName = "0";
var dbUserName = "0";
var dbPassword = "0";
var dbUrl = "0";


var register = function (email, pass1, pass2, name) {
    if (pass1 !== pass2) {
        result.SetRegister = "[{\"result\":\"Şifre doğrulaması yapılamadı\"}]";
    } else {
        var query = "INSERT INTO users (FullName,email,Pass) VALUES ('" + name + "','" + email + "','" + pass1 + "')";
        var url = "http://37.247.113.31:20083/Services/SetData.aspx?dbUrl=" + dbUrl + "&dbUName=" + dbUserName + "&dbPass=" + dbPassword + "&dbDbName=" + dbName + "&query=" + query;
        $http.get(url).success(function (data) { result.SetRegister = data; });
        $http.get(url).error(alert("ERROR"));
    }
};
result.SetRegister = register;
}]);

有什么问题?我该如何实现它? 最好的问候

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。 谢谢大家的回答。

JS

app.controller("SetRegister", ["$http", function ($http) {
var result = this;
var dbName = "0";
var dbUserName = "0";
var dbPassword = "0";
var dbUrl = "0";


var register = function (email, pass1, pass2, name) {
    if (pass1 !== pass2) {
        result.SetRegister = "[{\"result\":\"Şifre doğrulaması yapılamadı\"}]";
    } else {
        var query = "INSERT INTO users (FullName,email,Pass) VALUES ('" + name + "','" + email + "','" + pass1 + "')";
        var url = "http://37.247.113.31:20083/Services/SetData.aspx?dbUrl=" + dbUrl + "&dbUName=" + dbUserName + "&dbPass=" + dbPassword + "&dbDbName=" + dbName + "&query=" + query;
        $http.get(url).success(function(data) { result.SetRegister = data; });
        $http.get(url).error(function (data) { result.SetRegister = data; });
    }
};
result.SetRegister = register;

}]);

HTML

<md-button class="md-raised md-primary" ng-click="setreg.SetRegister(reg.email,reg.pass1,reg.pass2,reg.name);" style="width: 100%">

此发送请求问题和响应ok或FAIL eex消息。 service是db。中的数据。