当我更新表单上的操作时,它不会发布

时间:2014-03-10 04:50:30

标签: angularjs

这很好用

<head>
<script>
        function UsersCtrl($scope) {
            $scope.info = "The buttons haven't been clicked yet";
            $scope.signupfolks = function () {
            $scope.info = "You've cliked the first radio option!"
            $scope.actionyo = "/users/session";
        };
        $scope.loginfolks = function () {
            $scope.info = "You've cliked the second option!";
            $scope.actionyo = "/users/session2";
    };
    }


</script>

</head>


<body>
<div ng-controller="UsersCtrl">
<form action="/users/session" method="post">
<input type="radio" ng-model="CurrentFolks" ng-change="signupfolks()" name="NewFolks" id="optionsRadios1" value="NewFolks3">
<input type="radio" ng-model="CurrentFolks" ng-change="loginfolks()" name="NewFolks" id="optionsRadios2" value="CurrentFolks3">
<button type="submit">Sign In</button>
{{info}} <!-- verifies the angular's working for this example -->
</div>

这打破了它

改变

<form action="/users/session" method="post">

<form action="{{actionyo}}" method="post">

但是在“查看源”中它说

当我没有选择选项按钮时,它会显示:

<form action method="post">

当我选择一个选项按钮时,来源说:

<form action="/users/session" method="post">

但是当我点击提交按钮时......它不会去。没有任何事情发生。

1 个答案:

答案 0 :(得分:0)

我猜是因为在你点击任何选项按钮之前,actionyo还没有值?

尝试在控制器中首先设置一个值:

function UsersCtrl($scope) {
            $scope.actionyo = "/users/session"; //set a default. WARNING: IS THIS THE DEFAULT YOU WANT?
            $scope.info = "The button haven't been clicked yet";
            // all the rest of your code