Javascript 已填充关于ng选项的通知

Javascript 已填充关于ng选项的通知,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我遇到了一个问题,我想知道select元素何时完全填充并准备就绪,以便我可以在该select元素上执行第三方库函数。问题是我不知道angular什么时候完成处理 下面是一个场景 我有这个选择元素 <select id="studentDropDown" ng-model="student" ng-options="stu.studentId as stu.studentName for stu in studentList" ></select> $scope.$wat

我遇到了一个问题,我想知道select元素何时完全填充并准备就绪,以便我可以在该select元素上执行第三方库函数。问题是我不知道angular什么时候完成处理

下面是一个场景

我有这个
选择
元素

<select id="studentDropDown" ng-model="student" ng-options="stu.studentId as stu.studentName for stu in studentList" ></select>
$scope.$watch('studentList', function() {
           $timeout(function() {
               console.log("i am triggering");
               $('#studentDropDown').thirdPratyFn('refresh');
           });
    });
如果我在赋值之后执行第三方方法,那么它会创建一个下拉列表,没有
选项
元素,但如果我延迟500毫秒或1秒,那么它会创建一个包含所有值的下拉列表。但我需要合适的解决方案,这样代码也可以在速度较慢的机器/浏览器上运行

请建议更好的方法, 提前谢谢

编辑

我已经在我的控制器中添加了此代码,但现在它只在下拉列表中填充1个
选项
元素

<select id="studentDropDown" ng-model="student" ng-options="stu.studentId as stu.studentName for stu in studentList" ></select>
$scope.$watch('studentList', function() {
           $timeout(function() {
               console.log("i am triggering");
               $('#studentDropDown').thirdPratyFn('refresh');
           });
    });
编辑


我的错,在实现超时后,1
选项
元素的问题是第三方方法。DOM在那时已经完成并填充了

我想到了两种解决方案:

  • 在下一个事件循环中执行第三方插件代码。您可以使用$timeout服务来执行您的方法。e、 g

    .success(function (data, status, headers, config) 
      {
          $scope.studentList= data.studentList; 
          $timeout(fnToBeExecuted,0); //make sure to inject the $timeout service in your controller
      });
    
  • 写一个指令来完成你的工作。通过这种方式,您可以处理插件执行后要执行的任何数据绑定


  • 我的缺点是,在实现超时之后,第三方方法出现了1个选项元素的问题。DOM已完成并在此时填充