将参数传递给状态导致元素不显示

passing parameters to state is causing element to not show

在我的 AngularJS 应用程序中,我有一个表单,用户需要在其中输入申请编号,如果成功,则在下方显示相应数据的内容。如果我将此数据作为参数传递给当前 state,我只能通过 scope 访问该数据。我正在使用 ui-router 进行路由。

我读过诸如 Reloading current state - refresh data 之类的话题,它告诉我可以将数据传递到当前状态而不刷新页面,但它一直在刷新并且内容不显示。我也不确定我是否正确使用 ng-show and/or ng-if。我传递数据的函数如下:

vm.findPatent = function(patentNo) {
    searchPatentService.findPatent(patentNo)
    .then(
        function(data) {
            $state.go('.', { patent: data }, {reload: false, notify: false, location: false})
            })
        },
        function(errResponse) {
            console.error('Error while finding patent');
        }
    );
}

而我的参数在state内:

.state('search-patent', {
    url: '/search-patent',
    component: 'searchpatent',
    params: {
        navigation: 'patentnav',
        patent: null
    }
})

我的表单视图在表单提交时显示以下内容:

<form ng-submit="$ctrl.findPatent(searchPatent)" name="searchPatentForm">
    <fieldset>
        <div class="form-group row">
            <labelfor="searchPatent">EP No.</label>
            <div>
                <input type="text" name="searchPatent" ng-model="searchPatent" class="form-control" placeholder="Search" required>
            </div>
        <div>
            <button type="submit">Submit</button>
        </div>
    </div>
  </fieldset>
</form> 

<div class="row" ng-show="searchPatentForm.$submitted">
    <div class="col-md-12">
//ANOTHER FORM AND CONTENT WHICH IS DISPLAYED ON SUBMIT
    </div>
</div>

问题

如何在不刷新页面的情况下将数据传递到当前state?另外,使用ng-show是否有更好的解决方案?谢谢

因为您想在提交后留在页面上。

$scope.result= null;
vm.findPatent = function(patentNo) {
    searchPatentService.findPatent(patentNo)
    .then(
        function(data) {
            $scope.result=data;
            })
        },
        function(errResponse) {
            console.error('Error while finding patent');
        }
    );
}

在您看来,如果您希望重新创建 div,则应使用 ng-if,否则请使用 ng-show see details here

<div class="row" ng-if="result">
    <div class="col-md-12">
      {{result}}
    </div>
</div>

有关详细示例,请参阅 here