0
我對這項技術很陌生,並且詢問了許多人面臨的共同問題。我正在更新數據庫的日期,並在點擊按鈕上顯示「已成功發佈」等消息,但我希望日期也能在屏幕上更新。我嘗試添加刷新代碼,但是然後發佈的消息不顯示,但頁面被刷新並顯示更新的日期。我無法在單個按鈕單擊中執行這兩個操作。 簡而言之,我想在點擊按鈕時自動刷新頁面,並用消息顯示更新後的數據。Angularjs-上傳和更新頁面按鈕上的數據點擊
HTML代碼:
<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()">Publish</button>
</div>
<br/>
<div id="statusDivPublish" ng-show="showstatus">
<alert type="{{alert.type}}">{{alert.msg}}</alert>
</div>
</div>
</form>
</div>
JS代碼:
app.controller('PublishManifestCtrl', function ($scope, $rootScope, $http) {
$scope.showstatus = false;
$http({
url: $rootScope.WebApiURL + '/getmanifeststatus',
method:get(),
params: { 'foobar': new Date().getTime() }
}).
success(function (data, status, headers, config) {
var options = { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric" };
data.manifestLastedUpdatedDate = (new Date(data.lastUpdatedDateTime)).toLocaleDateString('en-US', options);
data.manifestLastPublishedDate = (new Date(data.lastPublishDateTime)).toLocaleDateString('en-US', options);
var date1 = new Date(data.lastUpdatedDateTime);
var date2 = new Date(data.lastPublishDateTime);
data.enablePublishButton = date2.getTime() > date1.getTime();
$scope.manifeststatus = data;
}).
error(function (data, status, headers, config) {
alert('error' + status);
// log error
});
$scope.Save = function (data) {
debugger;
$http.post($rootScope.WebApiURL + '/updatemanifeststatus');
$scope.showstatus = true;
$scope.alert = { type: 'success', msg: 'Published Successfully.' };
$(".statusDivPublish").show();
$(".statusDivPublish").remove();
)});
刷新我嘗試使用下面的代碼之後
$scope.Save = function (data) {
debugger;
$http.post($rootScope.WebApiURL + '/updatemanifeststatus');
//refresh
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
,然後其他的事情。但我不確定,我錯了。
您不在郵件中發送任何數據。爲什麼你有一個沒有用戶輸入字段的表單?你究竟想要保存什麼? – charlietfl