Reputation: 11
I am trying to change the color of a textarea
in an Angular app using jQuery but it does not work.
What should I do? It says $ is not defined
.
HTML:
<body>
<div ng-app="myApp" ng-controller="testController">
<textarea id="abc">abc
</textarea>
</div>
</body>
</html>
Angular js:
var app = angular.module('myApp', []);
app.controller('testController', function($scope, $http) {
var tdVal =$("#abc");
var x = tdVal.innerHTML;
tdVal.html ("<span style='color: rgba(220, 0, 0, 1)'>" + x"</span>");
});
Upvotes: 1
Views: 209
Reputation: 15442
it looks like you want to render HTML within textarea
tag, which is not allowed by browsers, but what you can do is to use editable div
element:
<div id="abc" contenteditable="true"></div>
check out Rendering HTML inside textarea
angular.element
by default uses jQueryLight which is limited version og jQuery. You should use ng-style
angular directive:
<div id="abc" contenteditable="true">
<span ng-style="{color: 'rgba(220, 0, 0, 1)'}">abc</span>
</div>
or you can assign to ng-style
your custom function which will return CSS object, according to your logic.
Upvotes: 0
Reputation: 161
Try this, it does work if there are not some other dependincies:
$('#abc').css('color', 'rgba(220, 0, 0, 1)');
Upvotes: 0
Reputation: 4094
You are not just changing color, but the control itself. If changing color is the intent:
var elem = angular.element('#abc');
elem.css('color', 'rgba(220, 0, 0, 1)');
for value update, angular provides you bind directive.
$scope.value = 'some value'
and in view
<textarea id="#abc" ng-bind="value"></textarea>
Upvotes: 1