【问题标题】:How to update $('select').material_select(); after $http complete如何更新 $('select').material_select(); $http 完成后
【发布时间】:2017-04-27 11:27:46
【问题描述】:

我正在使用 angular 和 materializecss (link)。我想在 $http 完成更新后material_select() 但找不到任何解决方案。

到目前为止我已经尝试过::

1> $('select').material_select();

2> $(element).material_select();

任何人都可以提出任何解决方案。

提前致谢。

【问题讨论】:

  • 你在说哪个 $http 调用?
  • 我正在通过角度 AND 调用 ajax .success 我正在使用该初始化函数。
  • 您是否在 $http 调用的 .success 中调用了 material_select()?
  • 可以,但是不知道怎么打。

标签: angularjs select materialize angular-http


【解决方案1】:

使用以下步骤解决您的答案::

 $http({
  method: "POST",
  url: '/xxxxxxx',
  data: {
   type: "1"
  }
 })
  .success(function (result) {
   //result-> [{value:1,name:val1},{}...]
   $scope.choices = result;

  //timeout use for resolving $digest issue of $scope
   $timeout(function () {
    angular.element(document).find('#mySelect').material_select();
   }, 500);

  });

$timeout 在您的控制器中使用此服务。

在您的 DOM 中,它将如下所示

<select class="" id="mySelect" material-select ng-model="accountType" ng-options="item.value as item.name for item in choices">
</select>

【讨论】:

  • 选择器没问题,但为什么要使用超时?
猜你喜欢
  • 2021-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-21
  • 2021-11-25
相关资源
最近更新 更多