本文介绍了如何将模型数据传递到发布请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取ng-model的值并将其放入控制器发布请求中?

How do I get the value of an ng-model and place it into a controller post request?

    (function(angular) {
    angular.module('urlShortener', ['ngAnimate'])
        .controller('shortenerController', function($scope, $http){
            $scope.customMode = false;
            $scope.passData = function passData(){
                $http.post('/add', {url: raw_url})
                    .success(function(data, status, headers, config) {
                        // this callback will be called asynchronously
                        // when the response is available
                    })
                    .error(function(data, status, headers, config) {
                        // called asynchronously if an error occurs
                        // or server returns response with an error status.
                    });
            }
        })


})(window.angular);

我正在使用的模型:

<input ng-model="raw_url" type="text" placeholder="Paste your url here and we will shrink it!" class="form-control"/>

推荐答案

从范围中读取它: $ scope.raw_url

文档:

这篇关于如何将模型数据传递到发布请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:39
查看更多