2017-03-09 40 views
0

視圖(question_to_vote)試圖改變來自控制器的模態值時,不會得到更新更新的模態值的變化。AngularJS,查看是沒有得到來自控制器

查看文件:question_to_vote.html

<div class="alert alert-success text-center" ng-show="c.message.success"> 
<strong>Success!</strong> Question Posted 
</div> 
<button ng-click="c.insert_public_q()"> Active </button> 

控制器:

app.controller("ques_controller",function($http,$state,$interval,$mdBottomSheet,$timeout){ 
    let vm = this; 
    vm.message = {success:true}; 
    vm.message.success = false; 

    vm.insert_public_q = function(){ 

    var upvote = {vote:1,name:"Mahesh"}; 
    $http({method:"post",url:"insert-top-downvote",data:{upvote:upvote}}).success(function(result){ 

     vm.message.success = true; 

     }); 


}) 

});

路線

var app = angular.module("around_a",['ui.router','ngMaterial']); 

app.config(function($interpolateProvider,$stateProvider,$urlRouterProvider){ 

    $interpolateProvider.startSymbol('[[').endSymbol(']]'); 

    $urlRouterProvider.otherwise('/home'); 

    $stateProvider 
    .state('add_ques.questions_to_vote',{ 
     url: '/questions-to-vote', 
     templateUrl:'questions_to_vote.html', 
     controller:'ques_controller as c' 
    }); 
}); 
+0

您檢查您的HTTP成功處理程序正在被調用? –

+0

你也可以檢查角度scope.apply。但它不應該被要求 –

+0

是的,如果我把警報在成功函數(「成功」),這是工作。 –

回答

0
<div class="alert alert-success text-center" ng-show="message.success"> 
<strong>Success!</strong> Question Posted 
</div> 
<button ng-click="c.insert_public_q()"> Active </button> 

沒有c.message.successmessage.success

和哦,是另一回事

app.controller("ques_controller",function($http,$state,$interval,$mdBottomSheet,$timeout,$scope){ 

    $scope.message = {success:true}; 
    $scope.message.success = false; 

    $scope.insert_public_q = function(){ 

    var upvote = {vote:1,name:"Mahesh"}; 
    $http({method:"post",url:"insert-top-downvote",data: {upvote:upvote}}).success(function(result){ 

     $scope.message.success = true; 

     }); 


}) 
+0

嘗試了它,但它不起作用 –

+0

使用範圍變量 –

+0

還有一些其他的原型繼承問題,我在使用範圍時遇到,所以我選擇了爲這種方法。 –