Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更改$watch中的作用域值不会反映在html中_Javascript_Angularjs - Fatal编程技术网

Javascript 更改$watch中的作用域值不会反映在html中

Javascript 更改$watch中的作用域值不会反映在html中,javascript,angularjs,Javascript,Angularjs,HTML 当$scope.something发生更改时,我会将新值分配给$scope.sme(请参阅监视方法)$html中的scope.sme没有任何值。但是,当我记录这些值时,我看到了更新后的值。我偶然看到了这篇文章,但我不明白如何将它应用到我的案例中-您通常不希望在回调的回调中附加$watchs。您还可以研究如何连锁承诺,以避免出现这种嵌套级别。此外,还将研究如何创建一个。它很可能会帮助您找到问题所在。我知道最好降低代码的复杂性。但是,我正在寻找一个快速修复方法。您通常不希望在回调的回调中附

HTML


当$scope.something发生更改时,我会将新值分配给$scope.sme(请参阅监视方法)$html中的scope.sme没有任何值。但是,当我记录这些值时,我看到了更新后的值。我偶然看到了这篇文章,但我不明白如何将它应用到我的案例中-

您通常不希望在回调的回调中附加$watchs。您还可以研究如何连锁承诺,以避免出现这种嵌套级别。此外,还将研究如何创建一个。它很可能会帮助您找到问题所在。我知道最好降低代码的复杂性。但是,我正在寻找一个快速修复方法。您通常不希望在回调的回调中附加$watchs。您还可以研究如何连锁承诺,以避免出现这种嵌套级别。此外,还将研究如何创建一个。它很可能会帮助您找到问题所在。我知道最好降低代码的复杂性。然而,我正在寻找一个快速解决方案。
 <nav-Header></nav-Header>
 <div ng-controller="loginController">
<div class="col-xs-8 col-sm-4 col-md-4 col-sm-offset-4 col-md-offset-4">
    <div class="input-group">
        <input type="text" class="form-control"
            placeholder="Search for a docType"
            typeahead-on-select="onSelect($item, $model, $label)"
            ng-model="selected" /> <span class="input-group-addon"
            ng-click="alert()"> <i
            class="glyphicon glyphicon-triangle-bottom"></i>
        </span>
    </div>

    sme= {{sme}}
</div>
(function() {
  'use strict';

  var ezControllers = angular.module('login.controller', ['com.doc.ui.components.message.services',
    'com.doc.ui.components.message.constants'
  ]);

  ezControllers.controller('loginController', [
    '$state',
    '$scope',
    '$log',
    '$window',
    'messageService',
    'messageCodesConstant',
    '$http',
    '$location',
    '$timeout',
    '$uibModal',
    '$interval',
    '$rootScope',
    'com.doc.ui.loginService',
    'com.doc.ui.dropdownService',
    function($state, $scope, $log, $window, messageService,
      messageCodesConstant, $http, $location, $timeout,
      $uibModal, $interval, $rootScope, loginService, dropdownService) {

      var self = this;

      // flag to keep track of service operation
      this.callInProgress = false;
      $scope.docList = null;

      $scope.something = null;

      // $scope.docList = "hi there";
      $scope.states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];
      /**
       * Authenticate the user
       */
      var call = $scope.authenticate = function(
        inUserName, inUserPassword) {



        // authenticate the user using service, and
        // if all good,
        // then forward to the home page
        self.callInProgress = true;
        loginService.authenticate(inUserName,
            inUserPassword)
          .then(
            // on successful
            // authentication
            function(userProfile) {




              dropdownService.getDocTypeList().then(
                // on successful
                // authentication
                function(docTypeList) {

                  // go to Search page
                  // directly


                  $log.log('docTypeList in controller:' + angular
                    .toJson(docTypeList.recordsList, true));

                  angular.forEach(docTypeList.recordsList, function(docType) {
                    console.log(docType.name);


                  })

                  // $scope.docList=docTypeList.recordsList;
                  $log.log('scope.docList:' + docTypeList.recordsList[0].name);

                  //setting new value
                  $scope.something = 'updated valuee';


                  $scope.$watch('something', function(newVal, oldVal) {
                    $log.log('newvalue: ' + newVal + ':oldval:' + oldVal);
                    $scope.sme = newVal;

                  });

                  $state
                    .go('home');

                },
                // on getting error
                function(errorMsg) {
                  $log
                    .error('Error in userlogin controller: ' + errorMsg);
                  messageService
                    .error(
                      messageCodesConstant.LOGIN_FAILURE,
                      "doc type list service Failure! Please try again. Error: " + errorMsg);
                },
                // update from service -
                // optional
                function(update) {
                  $log
                    .log('Update in userlogin controller: ' + update);
                }).finally(function() {
                $log.log('Service call to authenticate user ended.');
                self.callInProgress = false;
              });





            },
            // on getting error
            function(errorMessage) {
              $log
                .error('Error in userlogin controller: ' + errorMessage);
              messageService
                .error(
                  messageCodesConstant.LOGIN_FAILURE,
                  "Login Failure! Please try again. Error: " + errorMessage);
            },
            // update from service -
            // optional
            function(update) {
              $log
                .log('Update in userlogin controller: ' + update);
            }).finally(function() {
            $log.log('Service call to authenticate user ended.');
            self.callInProgress = false;
          });

      };



    }
  ]);


})();