有一个指令
app.directive('curSor', function () {
return {
restrict: "E",
template: '<div class="cursor-child"></div>',
link: function (scope, element, attr) {
const win = angular.element(window);
const elem = angular.element(element);
///////////////////////////////////////////////////////////
win.on('click', ()=>{
elem.children().addClass('cursor-child-active');
setTimeout(()=>{
elem.children().removeClass('cursor-child-active');
},200);
});
///////////////////////////////////////////////////////////
win.on('mousemove', function(e){
elem.css({
"top":e.pageY - "2" +"px",
"left":e.pageX - "2" +"px"
});
});
}
}
});
当我写这个例子的时候,我不能用 pure 来写JS
。
例如
window.addEventListener('click', () => {
console.log('win');
})
Angularjs 抛出一个错误,说这样的函数addEventListener
不存在。
问题...
是否可以AnguarJS
纯编写代码JS
?
这值得吗?
PS不想深入研究JQ...)))
不工作的例子...
const app = angular.module('app', []);
app.directive('curSor', function() {
return {
restrict: "E",
template: '<div class="cursor-child">CursorChild</div>',
link: function(scope, element, attr) {
const win = angular.element(window);
const elem = angular.element(element);
//elem.children().classList.add('cursor-child-active');
win.addEventListener('click', () => {
console.log('win');
})
}
}
});
<html ng-app="app">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
</head>
<body>
<cur-sor></cur-sor>
</body>
</html>
帮我把Angularjs理解到底,如何正确、称职地写在上面?我意识到最后一个问题太全球化了……
1 个回答