繁体   English   中英

UIBootstrap中断angularjs发布请求

[英]UIBootstrap breaking angularjs post request

我在偏角部分有以下内容

<h1>{{tournament.name}}</h1>
<accordion close-others="true">
    <accordion-group>
        <accordion-heading>
            <p>Schools</p>
        </accordion-heading>
        <input ng-model="newSchoolName" placeholder="new school name">
        <button class="btn-sm" ng-click="addNewSchool()" ng-disabled="!newSchoolName">Add New School</button><br/>
...

以及我控制器中的以下内容

tournamentControllers.controller("ConsoleController",['$scope','$http', function($scope, $http){

$scope.update = function(){
    console.log("update");
    $http({method:'GET', url: '/tournament/console_api'}).
        success(function(data,status,headers,config){
            $scope.tournament = data;
        }).error(function(data,status,headers,config){
            console.log("error");
    });//Initial schools
};
$scope.update();
$scope.addNewSchool = function(){
    $http.post('/tournament/add_school',{
        new_name : $scope.newSchoolName
    }).success(function(data,status,headers,config){
        $scope.tournament = data;
    }).error(function(data,status,headers,config){
        console.log("error");
    });
};

如果我注释掉ui.bootstrap部分(但不删除它们),它会很好地工作,但是如果我将它们留在其中,最终会发送空的JSON对象“ tournament” = {},我猜这是从这一行来的我说“ $ scope.tournament = data;”的地方,

我正在使用角度1.2.9,角度路由,角度清理ui.bootstrap 0.11.0和bootstrap.css。 提前致谢。

编辑:这是Rails控制台日志给出的发布请求的结果

参数:{“锦标赛” => {}}(不工作时)

参数:工作时的{“ new_name” =>“ gwgfwf”,“锦标赛” => {}}

在尝试了许多调试之后,它与在手风琴内部创建一个子作用域有关,该作用域不包括newSchoolName。 不知道如何解决这个问题。

您对子范围是正确的。

这个问题开始 :“ 您需要使用一个对象而不是原始对象

<input ng-model="school.newSchoolName" placeholder="new school name">
<button class="btn-sm" ng-click="addNewSchool()" ng-disabled="!school.newSchoolName">Add New School</button><br/>

和:

$http.post('/tournament/add_school',{
    new_name : $scope.school.newSchoolName
}

不要忘记声明$scope.school

$scope.school = {newSchoolName: ''};

我仍然不明白为什么您要发送tournament => {}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM