javascript - $scope not capturing variable in Angular -


i'm having problem want understand why behaving - i'm trying use last button on html page user 'jid' chat application, , way tried ng-model='jid' , ng-model='jid.jid', while in controller trying define in few ways $scope.jid' or $scope.jid = ""; or $scope.jid = {};

i'm confused why aren't working, because when put $scope.user.jid, using $scope.user = {} assume, works fine. not when made new $scope variable $scope.jid? when that, console prints out empty object.

.controller('chatctrl', function($scope, $stateparams, $rootscope, $ionicloading) {    console.log("inside chatctrl");        qb.createsession(function(err,result){      console.log('session create callback', err, result);      console.log(json.stringify(err));      console.log(json.stringify(result));    });        $scope.settings = {};    $scope.user = {};    $scope.error = {};    $scope.jid = {};      $scope.signinclick = function() {      console.log('login clicked');             var params = {'login': ($scope.user.username), 'password': ($scope.user.password)}        console.log("params... " + json.stringify(params));          qb.users.create(params, function(err, user){          if (user) {            console.log("successful user.create... " + json.stringify(user));            var jid = user.id + "-23837" + "@chat.quickblox.com";            console.log(user.login + "'s jid is......" + jid);            var chatparams = {'jid': jid, 'password': ($scope.user.password)};            qb.chat.connect(chatparams, function(err, roster) {              console.log(json.stringify(err));              console.log(json.stringify(roster));            });          }           else  {            console.log(json.stringify(err));            if (err.message == "unprocessable entity"){              qb.login(params, function(err, user){                if (user) {                  console.log("logged qb " + json.stringify(user));                  var jid = user.id + "-23837" + "@chat.quickblox.com";                  console.log(user.login + "'s jid is......" + jid);                  var chatparams = {'jid': jid, 'password': ($scope.user.password)};                  qb.chat.connect(chatparams, function(err, roster) {                    console.log("stringifying err... " + json.stringify(err));                    console.log("stringifying roster... " + json.stringify(roster));                  });                }                 else  {                  console.log(json.stringify(err));                }              });            }          }        });      $scope.getjidclick = function(){      var jid = $scope.jid.jid      console.log("jid is.... " + json.stringify(jid));    }    $scope.sendmessageclick = function() {      console.log('sendmessageclick');      qb.chat.send(jid, {        type: 'chat',        body: 'hello world!'      });    };    })
          <label class="item item-input">              <input type="text" placeholder="user name" ng-model="user.username">            </label>            <label class="item item-input">              <input type="text" placeholder="password" ng-model="user.password">            </label>            <button class="button button-full button-balanced" data-ng-click="signinclick()">             sign in            </button>                <label class="item item-input">              <input type="text" placeholder="input message!" ng-model="user.message">            </label>            <button class="button button-full button-balanced" data-ng-click="sendmessageclick()">             send message            </button>            <label class="item item-input">              <input type="text" placeholder="jid" ng-model="jid">            </label>            <button class="button button-full button-balanced" data-ng-click="getjidclick()">              user?            </button>

you don't need declare this:

$scope.jid = {}; //the controller pick value automatically 

and inside getjidclick

$scope.getjidclick = function(){     var jid = $scope.jid; //this should job     console.log("jid is.... " + jid);   } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -