javascript - 在 AngularJS 中使用 jqLit​​e 附加文本

标签 javascript angularjs jqlite

我正在尝试将 html 附加到页面上的第一个 h1 之后。 angular.element 返回 h1 元素,但它没有附加文本“hello!”在 h1 元素之后。尽量避免使用完整的 JQuery。有人有想法吗?

app.controller('Test', ['$scope', function ($scope) {
    var h1 = angular.element(document).find("h1").length > 0 ? angular.element(document).find("h1")[0] : null

    if (h1 != null) {
        angular.element(h1).after(function () {
            return "hello!"
        })
    }
}]);

最佳答案

不要在 after 中传递函数,只需包含所需的文本作为参数即可。

if (h1 != null) {
        angular.element(h1).after('Hello')
}

关于javascript - 在 AngularJS 中使用 jqLit​​e 附加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37699741/

相关文章:

javascript - 放置 id X 的可拖动元素以放置 id Y 的容器

javascript - 如何在动态表中插入数组的某些值作为 <td> 的 CSS 样式属性?

javascript - 通过具有日期值的单个键对对象数组进行排序

javascript - 当我的结果有限时,如何对API结果进行分页?

angularjs - Android Phonegap 应用 + AngularJS : Update $scope with selected date on android DatePicker

javascript - 在新的浏览器窗口中打开 thymeleaf 链接

javascript - 如何在 Javascript 或 Angularjs 中找到相等的对象?

javascript - 通过类/id 从附加元素中删除标签

javascript - 在 angular-js 应用程序中使用 Google 跟踪代码管理器 'click-listener' 时,“无法对数据层进行字符串化”

javascript - 如何使用 JqLite 或 javascript 删除 HTML 元素