为什么不起作用angular.element('<p>').css('color', 'red');
?
angular
.module('app', [])
.controller('MainController', MainController)
;
function MainController() {
// angular.element('p').css('color', 'red'); ERROR. Now I see what the docs meant by "HTML String"
// angular.element('<p>').css('color', 'red'); No error, but doesn't work
angular.element(document.querySelector('p')).css('color', 'red'); // Works
}
<!DOCTYPE html>
<html ng-app='app'>
<head>
<script data-require="angular.js@1.4.6" data-semver="1.4.6" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-controller='MainController as vm'>
<p>test</p>
</body>
</html>