替换AngularJS中的ng-view html内容

时间:2014-05-29 06:54:33

标签: javascript angularjs

我在ng-view中有一个表单,使用$ http调用提交,我在表单提交时得到html。我想用响应html替换ng-view内容。有可能吗?

formSubmit($event, <action_url>)是表格ng-submit属性的值

// controller
$scope.formSubmit = function (e, action) {
        e.preventDefault();
        var form = $(e.currentTarget),
            data = null,
            submitBtn = form.find('button[type=submit]');
        if(!validate.form(form)) {
            console.log('form validation failed..!!');
            return false;
        }
        data = form.serialize();
        data += '&'+submitBtn.attr('name') +'='+ submitBtn.attr('value');
        $http({
            'method': 'post',
            'url': action+'&format=ng',
            'data': data,
            'headers' : { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function(data, status, headers, config) {
            // HERE I WANT TO PUT `data` IN NG-VIEW
        });
    }

// Form
<form method="post" id="RegistrationForm" name="RegistrationForm" ng-submit="formSubmit($event,'<MY_URL>')" class="ng-pristine ng-valid" novalidate="novalidate">
    <fieldset>
        <div class="form-row   required ">
            <label for="profile_customer_email">
                <span>Email*</span>
            </label>
            <input class="input-text email required valid" autocomplete="off" id="profile_customer_email" type="text" name="profile_customer_email" value="" maxlength="50">
        </div>
    </fieldset>
</form>

0 个答案:

没有答案