我有一个选择输入来加载模型中的选项:
<select data-custom-select ng-model="adAccount" ng-options="adAccount.name for adAccount in adAccounts" class="cs-select cs-skin-border ad-accounts-select" >
<option value="">Select an Ad Account</option>
</select>
我需要在填充选项后运行一些javascript。我创建了这个指令:
(function(){
'use strict';
define([
'config',
'angular',
'selectFx',
'application-modules/directives'
], function(config, angular, selectFx){
var moduleId = 'customSelect';
angular.module(config.app.name + '.directives').directive(moduleId, function($timeout){
return {
restrict: 'AEC',
link: function(scope, element, attrs){
$timeout(function () {
var sel = angular.element(element)[0];
new SelectFx(sel);
});
}
};
});
});
})();
在填写选项之前,$timeout
内的代码会被调用。