javascript - AngularJS 在使用 ng-switch 渲染后执行

标签 javascript jquery angularjs

我创建了一个隐藏和显示“页面”的 ng-switch,对于一些我需要运行 jQuery 选择器函数的元素。但是因为 Angular 会销毁并创建用于呈现的元素,所以我需要一种重新应用此 jquery 选择器函数的方法。

我的第一次尝试只是在元素中包含一个标记,但它只在页面第一次呈现时执行。

更新:

HTML:

<wizard-step ng-switch-when="customer">
    <h1>Customer Details</h1>

    <div class="step-content">
        <form role="form">
            <div class="form-group float-label-control">
                <label for="first_name">First Name</label>
                <input type="email" class="form-control" placeholder="First Name" name="first_name" ng-model="currentCase.customer.first_name">
            </div>
            <div class="form-group float-label-control">
                <label for="">Last Name</label>
                <input type="text" class="form-control" placeholder="Last Name">
            </div>
            <div class="form-group float-label-control">
                <label for="">Textarea</label>
                <textarea class="form-control" placeholder="Textarea" rows="1"></textarea>
            </div>
        </form>
    </div>
    <div class="btn-group">
        <input type="submit" ng-click="previousStep()" value="&laquo; Pending Cases " class="btn btn-warning" />
        <input type="submit" ng-click="nextStep()" value="Products &raquo;" class="btn btn-info" />
    </div>

    <script>
        if (window.jQuery) {
            $('.float-label-control').floatLabels();
        }
        console.log('float trigger');
    </script>
</wizard-step>

jQuery:

$('.float-label-control').floatLabels();

最佳答案

这似乎不适用于文本区域,但我在这里使用了代码:

http://clubdesign.github.io/floatlabels.js/

创建这个:

http://plnkr.co/edit/DH3zdvoCwAFOxc4pahkI?p=preview

关键部分是定义一个指令:

directive("floatLabels", function(){
  return {
    restrict: "A",
    link:function(scope, iElem, iAttrs){
      iElem.floatlabel()
      console.log(iElem)
    }
  }
})

应用该指令:

<input
   type="text"
   class="form-control"
   placeholder="Last Name"
   float-labels/>

关于javascript - AngularJS 在使用 ng-switch 渲染后执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23986635/

相关文章:

javascript - 如何将 html <span> 中的项目添加到 JavaScript 中的数组?

javascript - 在 jquery 事件后检索随机数

javascript - JavaScript Controller 中的 Angular JS 过滤

javascript - 如何转义字符串中的多个层次引号(HTML)

javascript - 使用 angular $http.get 从服务器下载文件

javascript - 文档只能用 jQuery 加载

javascript - RequireJS:两个模块可以相互依赖吗?

javascript - 确保文本字段以特定值 : jQuery 开头

Javascript:根据多个值过滤对象数组

javascript - Facebook 喜欢 popover 设置菜单 jquery 和 css