gpt4 book ai didi

javascript - 将 JavaScript 函数放入 Angularjs 文件中

转载 作者:行者123 更新时间:2023-11-30 17:12:07 25 4
gpt4 key购买 nike

我的 JavaScript 和 Angularjs 是这样的:

...
var propertiesModule = angular.module('xxx.properties', []);

propertiesModule.controller('PropertiesCtrl', ['$scope', '$routeParams', 'PropertiesService', 'ApplicationService', 'PlatformService', 'Page', function ($scope, $routeParams, PropertiesService, ApplicationService, PlatformService, Page) {
...
}]);

我想调用这样的 jQuery 功能

...
$("input[type=button]").click(function () {
$("#wrapper tr").prettyTextDiff({
cleanup: $("#cleanup").is(":checked")
});
});
...

我把我的文件放在最后但功能没有执行,为什么?

最佳答案

使用指令来处理 dom。并且 angular 有自己的处理 dom 的方法,使用 jquery 是个坏主意。这里有一些代码可以帮助

 app.directive('myDomDirective', function () {
return {
link: function ($scope, element, attrs) {
element.bind('click', function () {
element.html('You clicked me!');
// do your stuff
});

}
};
});

和一个帮助你学习的链接 angular directives

关于javascript - 将 JavaScript 函数放入 Angularjs 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26775464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com