admin管理员组文章数量:1025482
I have an input with type color defined in my controller scope:
HTML:
<div ng-controller="MyCtrl">
<input type="color" value="#f0f0f0" />
<input type="color" value={{getColor()}} />
</div>
JS:
function MyCtrl($scope) {
$scope.getColor = function () {
return "#f0f0f0";
};
}
The problem is the color don't get updated when its set by Angular, although when inspecting I see this:
See: FIDDLE.
How to update html5 input color dynamically?
I have an input with type color defined in my controller scope:
HTML:
<div ng-controller="MyCtrl">
<input type="color" value="#f0f0f0" />
<input type="color" value={{getColor()}} />
</div>
JS:
function MyCtrl($scope) {
$scope.getColor = function () {
return "#f0f0f0";
};
}
The problem is the color don't get updated when its set by Angular, although when inspecting I see this:
See: FIDDLE.
How to update html5 input color dynamically?
Share Improve this question asked Nov 12, 2014 at 9:11 OfirisOfiris 6,1516 gold badges37 silver badges59 bronze badges 1- I don't know whether the JSFiddle has been updated, but the color was changing for me. Just had a slight delay. – Stacker-flow Commented Nov 12, 2014 at 9:18
2 Answers
Reset to default 4Try to bind it to your controller with ng-model instead of value.
function MyCtrl($scope) {
$scope.mycolor = "#f0f0f0";
$scope.$watch('mycolor', function(newVal) {
console.log('newVal ' + newVal);
});
}
Here is updated and working fiddle.
You don`t even need a $watch, just a $timeout.
function MyCtrl($scope, $timeout) {
$timeout(() => {
$scope.mycolor = "#f0f0f0";
})
}
working fiddle http://jsfiddle/3ukL3suf/
I have an input with type color defined in my controller scope:
HTML:
<div ng-controller="MyCtrl">
<input type="color" value="#f0f0f0" />
<input type="color" value={{getColor()}} />
</div>
JS:
function MyCtrl($scope) {
$scope.getColor = function () {
return "#f0f0f0";
};
}
The problem is the color don't get updated when its set by Angular, although when inspecting I see this:
See: FIDDLE.
How to update html5 input color dynamically?
I have an input with type color defined in my controller scope:
HTML:
<div ng-controller="MyCtrl">
<input type="color" value="#f0f0f0" />
<input type="color" value={{getColor()}} />
</div>
JS:
function MyCtrl($scope) {
$scope.getColor = function () {
return "#f0f0f0";
};
}
The problem is the color don't get updated when its set by Angular, although when inspecting I see this:
See: FIDDLE.
How to update html5 input color dynamically?
Share Improve this question asked Nov 12, 2014 at 9:11 OfirisOfiris 6,1516 gold badges37 silver badges59 bronze badges 1- I don't know whether the JSFiddle has been updated, but the color was changing for me. Just had a slight delay. – Stacker-flow Commented Nov 12, 2014 at 9:18
2 Answers
Reset to default 4Try to bind it to your controller with ng-model instead of value.
function MyCtrl($scope) {
$scope.mycolor = "#f0f0f0";
$scope.$watch('mycolor', function(newVal) {
console.log('newVal ' + newVal);
});
}
Here is updated and working fiddle.
You don`t even need a $watch, just a $timeout.
function MyCtrl($scope, $timeout) {
$timeout(() => {
$scope.mycolor = "#f0f0f0";
})
}
working fiddle http://jsfiddle/3ukL3suf/
本文标签: javascriptAngularJS with html5 color inputset value dynamicallyStack Overflow
版权声明:本文标题:javascript - AngularJS with html5 color input - set value dynamically - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745636712a2160494.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论