angularjs - 将 ngModel 指令添加到 Javascript 中的动态元素
问题描述
有没有办法使用 javascript 将 ng-model 指令应用于创建的元素?在下面的代码中,我希望使用 ng-model 将新的选择元素绑定到控制器内的作用域变量:
angular.module('myApp').directive('dynamicHtml', function ($q, $http, $compile) {
return {
restrict: 'EAC',
scope: '=',
compile: function(element, attr) {
return function(scope, element, attr) {
var select = document.createElement('select');
// Here I want to use javascript to apply ng-model='controllerVar'
// to the new select element
element.append(select);
}
}
};
});
解决方案
哎呀-我很抱歉...我忘了编译东西...继续。
推荐阅读
- swift - 快速将图像存储在 Core Data 中
- drupal - 弹出窗口中的drupal 7条款和条件
- python - 使用 Pandas Dataframe 选择要从 MySQL 导出到 Excel 的列
- excel - VBA删除一列并添加新列,这些更改后如何在公式中引用相同的范围区域?
- c - 在c中将新节点作为头推送后节点的名称是什么?
- python - 如何在python中的多行字符串中提取两个子字符串之间的字符串部分
- python - 从 Keras 序列模型中恢复原始类标签
- c# - 从 HashSet 中获取 3 个随机元素和 1 个预设元素
- android - 如果在 aar 库中声明了依赖项,我是否需要在应用程序的 build.gradle 中删除同一个库?
- c# - 测试的字典或代表列表,值未知