AngularJS,View未获得有关控制器的模态值更改的更新

时间:2017-03-09 10:19:31

标签: javascript angularjs

尝试从控制器更改模态值时,

视图(question_to_vote)未获得更新。

  

查看文件: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'
    });
});

1 个答案:

答案 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.success

没有message.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;

      });


})