Javascript 在一次单击中调用2个函数

Javascript 在一次单击中调用2个函数,javascript,html,angularjs,Javascript,Html,Angularjs,我在ng click上调用两个函数。但它不起作用。我不确定在通过调试器进行交叉检查时为什么不调用Refresh1() HTML CODE <div class="row" ng-controller="PublishManifestCtrl"> <div class="col-xs-12 col-md-12"> <div class="widget"> <div class="widget-header bordered-bott

我在ng click上调用两个函数。但它不起作用。我不确定在通过调试器进行交叉检查时为什么不调用Refresh1()

HTML CODE
<div class="row" ng-controller="PublishManifestCtrl">
<div class="col-xs-12 col-md-12">
    <div class="widget">
        <div class="widget-header bordered-bottom bordered-themeprimary">
            <i class="widget-icon fa fa-tasks themeprimary"></i>
            <span class="widget-caption themeprimary">Manifest Status</span>
        </div>
        <div class="widget-body">
            <form class="form-bordered" role="form">
                <div class="form-group">
                    <label style="padding-left: 8px;">Manifest was last published to agents on <b>{{manifeststatus.manifestLastPublishedDate}}</b>.</label>
                </div>
                <div class="form-group">
                    <label style="padding-left: 8px;">Manifest was last updated by <b> {{manifeststatus.lastUpdatedByUser}} </b> on <b>{{manifeststatus.manifestLastedUpdatedDate}}</b>.</label>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-1">
                        **<button id="PublishButton" class="btn btn-default shiny " ng-disabled="manifeststatus.enablePublishButton" ng-click="Save(manifeststatus);Refresh1()">Publish</button>**
                    </div>
                    <br/>
                    <div id="statusDivPublish" ng-show="showstatus">
                        <alert type="{{alert.type}}">{{alert.msg}}</alert>
                    </div>
                </div>
            </form>
        </div>
新代码

 $scope.Save = function (data) {
       debugger;
        $http.post($rootScope.WebApiURL + '/updatemanifeststatus');
        //$http.get({ url: $rootScope.WebApiURL + '/getmanifeststatus' });

        $scope.manifeststatus = data;

        $scope.showstatus = true;
        $scope.alert = { type: 'success', msg: 'Published Successfully.' };
        $(".statusDivPublish").show();

        $scope.Refresh1();

    }

    $scope.Refresh1 = function ($rootScope, $state, $stateParams) {
        debugger;
         return {
            restrict: 'AC',
            link: function (scope, el, attr) {
                el.on('click', function () {
                    $state.transitionTo($state.current, $stateParams, {
                        reload: true,
                        inherit: false,
                        notify: true
                    });
                });
            }
        };
    };
 });
第一个函数更新并显示成功消息,而第二个函数刷新页面。

使用此函数

在第一个函数内调用refresh并将其从ng click中删除


更新
你有不同类型的问题,我也有。如果你试图刷新一个方法中的状态,用这个代码片段解决这个问题真的很困难



这并不难,但它的表现并不像你理解的那样


更新
获取您的代码

$scope.Refresh1 = function () {
    //refresh
    $state.go($state.current, {}, {reload: true});
}    

只需创建第三个函数,如:

function3(data) {
    save(data);
    refresh1();
}

不要一次执行两个函数
ng单击
,而是将
Refresh1
调用添加到
Save
调用的末尾,如下所示

HTML

<button id="PublishButton" 
        class="btn btn-default shiny " 
        ng-disabled="manifeststatus.enablePublishButton" 
        ng-click="Save(manifeststatus)">Publish</button>
更新

如果您使用的是
AngularJS V1.2.2
或更高版本,然后使用
ui router
,则以下操作可以重新加载数据

$state.transitionTo($state.current, $stateParams, {
    reload: true,
    inherit: false,
    notify: true
});
实现这一目标的最短方法是:

$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams
同样值得注意的是,这些都不会真正重新加载页面。如果要重新加载状态和页面,则没有用于该状态和页面的
ui-router
方法。执行
window.location.reload(true)

更新2

如果您收到:

$state未在作用域中定义。$Scope.Refresh1 (publishmanifest.js:44)位于Scope.$Scope.Save(publishmanifest.js:37) 在angular touch的$parseFunctionCall(angular.js:12345)处。js:472处 范围。$eval(angular.js:14401)位于范围。$apply(angular.js:14500)位于范围 HTMLButtoneElement。(angular touch.js:471)在 HTMLButtonElement.n.event.dispatch(jquery.min.js:3)位于 HTMLButtonElement.r.handle(jquery.min.js:3)

您没有在
控制器中注入
$state
服务。你必须这样做才能使用它

//without annotation (inferred, not safe when minifying code)
function Controller($scope, $state) {...}

//inline annotation
module.controller('Controller', ['$scope','$state', function($scope, $state) {...}]);

//$inject property annotation
function Controller($scope, $state) {...}
Controller.$inject = ['$scope', '$state'];

选择上述方法之一,将控制器设置为使用
$state

在save-in
$http
处理程序中调用refresh怎么样

像这样:

$http.post($rootScope.WebApiURL + '/updatemanifeststatus')
    .then(function(){
        $scope.Refresh1();
    });

该消息已显示,但日期未刷新。您能否编辑我现在发布的代码,以及当前状态的/*名称?我没有得到它。ReferenceError:$state未在作用域中定义。$Scope.Refresh1(publishmanifest.js:44)在作用域中定义。$Scope.Save(publishmanifest.js:37)在$parseFunctionCall(angular.js:12345)在angular touch.js:472在作用域中定义。$eval(angular.js:14401)在HtmlButtoneElement中定义。$apply(angular.js:14500)。(angular touch.js:471)在HTMLButtonElement.n.event.dispatch(jquery.min.js:3)在HTMLButtonElement.r.handle(jquery.min.js:3)它抛出一个arror of state is undefinedit似乎您没有注入$state您使用的是什么版本的angular?当我尝试使用刷新片段时,它抛出$state is undefined异常*@license AngularJS v1.3。13@SonamG您必须插入
$state
检查我的更新答案。我可以在JS文件本身中使用注释吗?
$state.transitionTo($state.current, $stateParams, {
    reload: true,
    inherit: false,
    notify: true
});
$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams
//without annotation (inferred, not safe when minifying code)
function Controller($scope, $state) {...}

//inline annotation
module.controller('Controller', ['$scope','$state', function($scope, $state) {...}]);

//$inject property annotation
function Controller($scope, $state) {...}
Controller.$inject = ['$scope', '$state'];
$http.post($rootScope.WebApiURL + '/updatemanifeststatus')
    .then(function(){
        $scope.Refresh1();
    });