2017-03-09 89 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

还有一些其他的原型继承问题,我在使用范围时遇到,所以我选择了为这种方法。 –