首页 > 解决方案 > 重新加载/提交后,角度应用程序从wordpress中删除输入表单

问题描述

我有一个表格:

<table class="widefat" ng-app="myApp" ng-controller="MyCtrl">
    <tr>
        <td><label for="name_pokemon"><?php _e( "Name", "cpt" ); ?></label></td>
        <td><input id="name_pokemon_val" maxlength="{{a1Max}}" name="name_pokemon" type="text" ng-model="a1" ng-change="update()" value="<?php echo esc_textarea( get_post_meta($post->ID, 'name_pokemon', true) ); ?>" placeholder="<?php esc_attr_e( 'Name', 'cpt' ); ?>"></td>
        <td>Length: {{a1.length}} Remaining: {{remainingA}}</td>
    </tr></table>

我的脚本:

<script>
            var myApp = angular.module('myApp',[]);

            function MyCtrl($scope) {
                    $scope.a1='';
                   
                var maxA = 21;
          
                $scope.update = function()  {
                    $scope.remainingA = maxA - ($scope.a1.length);

                    $scope.a1Max = maxA;
                    
                }
                $scope.update();}</script>

        

现在我遇到的问题是,在我提交自定义帖子类型后,它会重置输入数据。

我该如何解决?

感谢您的帮助

标签: javascriptangularjswordpresscustom-post-typewordpress-plugin-creation

解决方案


在这里发现了类似的问题

角度应用程序只显示应用程序的值...我通过使用 wordpress 的值初始化应用程序的 var 来修复它

现在看起来像这样:

$scope.a1='<?php echo esc_textarea( get_post_meta($post->ID, 'name_pokemon', true) ); ?>'; 
                    $scope.a2='<?php echo esc_textarea( get_post_meta($post->ID, 'code_card_pokemon', true) ); ?>';
                    $scope.b1='<?php echo esc_textarea( get_post_meta($post->ID, 'lang_pokemon', true) ); ?>';
                    $scope.b2='<?php echo esc_textarea( get_post_meta($post->ID, 'code_pokemon', true) ); ?>';
                    $scope.c1='<?php echo esc_textarea( get_post_meta($post->ID, 'setname_pokemon', true) ); ?>';

初始化范围后,它工作得很好。

我希望我能帮助别人


推荐阅读