【问题标题】:AngularJS Bootstrap UI TypeAhead on-select does not update ng-switchAngularJS Bootstrap UI TypeAhead on-select 不更新 ng-switch
【发布时间】:2014-01-07 12:52:36
【问题描述】:

我对 Angular 有点陌生,我想知道为什么在使用 Angular Bootstrap UI 的 Typeahead 时,我无法更新 ng-switch。

基本上,我要做的是根据列表中的选择更新视图。

%input{"ng-model" => "selectedPatient", type: 'text', typeahead: "patient as patient.first_name for patient in patients | filter:{first_name: $viewValue} | limitTo:8", 'typeahead-on-select'=>'onSelect($item)', placeholder: 'Enter Patient Name'}

这很好用,而且 onSelect 功能也很好用:

$scope.onSelect = function($item) {
  if ($item.visit == null || $item.visit.state == null){
    $scope.status = 'new';
  } else{
    $scope.status = 'old';;
  }
};

如果我将 $scope.$watch 放在“状态”上,那么我会看到它正在更新。但是,视图不会更新。

如果我只是通过 ng-click 来更新状态,那么一切正常。

任何想法将不胜感激。

【问题讨论】:

    标签: javascript angularjs ng-switch angular-ui-typeahead


    【解决方案1】:

    解决了。我没有意识到声明控制器会创建范围的实例。我在两个不同的部分声明了同一个控制器,因此作用域不一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多