在$ routeProvider templateUrl中获取结果

时间:2020-08-14 11:19:23

标签: angularjs

我尝试将一个templateUrl中的表单值传递给另一个contact.html到contact-success.html

我的资料来源: [app.js]

yApp.config(['$routeProvider', function($routeProvider){

    $routeProvider
        .when('/contact', {
            templateUrl: 'views/contact.html',
            controller: 'ContactController'
        })
        .when('/contact-success', {
            templateUrl: 'views/contact-success.html',
            controller: 'ContactController'
        })
    })
}]);

myApp.controller('ContactController', ['$scope', '$location', function($scope, $location,){
    $scope.sendMessage = function(contact){
        $scope.contact = contact;
        $location.path('contact-success');
    };
}]);

[contact.html]

<form name="contactForm" ng-submit="sendMessage(contact)" novalidate>
    <input type="text" placeholder="Please enter your name" name="name" ng-model="contact.name" ng-required="true"/>
    <div ng-show="contactForm.name.$touched && contactForm.name.$invalid">
        <small style="color: red; display: block; text-align: center;">Enter a valid name</small>
    </div>
    <input type="email" placeholder="Please enter your Email address" name="email" ng-model="contact.email" ng-required="true" />
    <div ng-show="contactForm.email.$touched && contactForm.email.$invalid">
        <small style="color: red; display: block; text-align: center;">Enter a valid email</small>
    </div>
    <textarea name="message" placeholder="Your message" ng-model="contact.message" ng-required="true"></textarea>
    <div ng-show="contactForm.message.$touched && contactForm.message.$invalid">
        <small style="color: red; display: block; text-align: center;">Enter a message</small>
    </div>
    <input type="submit" value="Send" ng-disabled="contactForm.$invalid" />
</form>

但是在此联系表单中输入的数据不会传递到contact-success.html页面。 该怎么做?

0 个答案:

没有答案
相关问题