Javascript AngularJS指令,用户输入后更改模板
我现在有一个指令,它在最初创建时只提供了一个下拉菜单来选择不同类型的东西。一旦用户选择了类型,我想更改模板 我试过使用下面的方法。在我的链接函数中Javascript AngularJS指令,用户输入后更改模板,javascript,angularjs,Javascript,Angularjs,我现在有一个指令,它在最初创建时只提供了一个下拉菜单来选择不同类型的东西。一旦用户选择了类型,我想更改模板 我试过使用下面的方法。在我的链接函数中 scope.nrAttrs = attrs; scope.layerIndex = attrs.index; scope.$watch(function () { var currentSlate = scope.$parent.$parent.current_slate_index; return scope.$parent.$paren
scope.nrAttrs = attrs;
scope.layerIndex = attrs.index;
scope.$watch(function () {
var currentSlate = scope.$parent.$parent.current_slate_index;
return scope.$parent.$parent.stage.slates[currentSlate].layers[scope.layerIndex].type;
}, function (oldVal, newVal, scope) {
htmlReplace(newVal, scope.nrEle, scope);
});
htmlReplace函数是:
var htmlReplace = function (layerType, element, scope) {
$http.get(layerPartials[layerType]).success(function (tplContent) {
element.html($compile(tplContent)(scope));
});
})
但是,我看到手表触发,但模板保持不变
需要任何建议或更多信息吗
编辑:@Fals我添加了编译,但仍然看到相同的结果。还有什么我可能遗漏的吗?根据要求,这里是ngSwitch的一个示例:
<form class="form-horizontal row" name="createProfileForm" role="form" novalidate>
<div ng-switch on="createProfileState" class="fill">
<div ng-switch-when="user">
<ng-include src="'views/templates/login/create-account/td-create-account-user.html'"></ng-include>
</div>
<div ng-switch-when="tutor">
<ng-include src="'views/templates/login/create-account/td-create-account-tutor.html'"></ng-include>
</div>
</div>
</form>
我们使用“on”来指定哪个范围参数负责更改,然后根据具体的值,我们可以使用ng include来呈现不同的模板,当然,它们都将在相同的控制器和作用域中运行您必须$compile元素听起来像您在寻找的一样ngSwitch@Jony-你能解释一下这是怎么回事吗?或者显示一个小示例?现在将以这种方式尝试并报告。我尝试了这种方法,但当我更新“打开”值时,模板保持默认值。这样做有效,错误是因为html注释-_-