AngularJS指令,用户输入后更改模板

时间:2015-07-15 19:52:10

标签: javascript angularjs

我目前有一个指令,在最初创建时只提供一个下拉菜单来选择不同类型的东西。一旦用户选择了类型,我想更改模板。

我尝试过使用以下内容。在我的链接功能

var backgroundMusicPlayer:AVAudioPlayer = AVAudioPlayer()

htmlReplace函数是:

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);
});

};

但是,我看到手表触发,但模板保持不变。

需要任何建议或更多信息?

编辑:@Fals我添加了编译,但我仍然看到相同的结果。还有其他我可能会遗失的东西吗?

1 个答案:

答案 0 :(得分:0)

这里要求的是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>

我们使用&#34; on&#34;指定哪个范围参数负责更改,然后根据具体值我们可以使用ng-include渲染不同的模板,自然它们都将在同一控制器和范围内运行