Blinking color sequence in Angular












-1















I have a task to create 4 blinking divs in an Angular project. The colors come from an API in an array with 16 elements and each element is an array with 4 elements (string).



ColorPatterns[
Pattern1["Color1", "Color2", "Color3", "Color4"],
Pattern2["Color1", "Color2", "Color3", "Color4"],
...
Pattern16["Color1", "Color2", "Color3", "Color4"],
]


Color1 is for the first div, Color2 is for the second div and so on.
The sequence of 16 must change per 1 second and after the last element (Pattern16) the sequence should start over: Pattern1 -> Pattern2 -> ... -> Pattern16 -> Pattern1 -> ... .
How should this problem be solved in Angular?










share|improve this question

























  • Well, how far is your own code to this? I can't imagine that you got this task without having ever written any line of code yourself. This page is not supposed to do your homework, but to help you finding the errors in it.

    – Lynx 242
    Mar 29 '18 at 17:27
















-1















I have a task to create 4 blinking divs in an Angular project. The colors come from an API in an array with 16 elements and each element is an array with 4 elements (string).



ColorPatterns[
Pattern1["Color1", "Color2", "Color3", "Color4"],
Pattern2["Color1", "Color2", "Color3", "Color4"],
...
Pattern16["Color1", "Color2", "Color3", "Color4"],
]


Color1 is for the first div, Color2 is for the second div and so on.
The sequence of 16 must change per 1 second and after the last element (Pattern16) the sequence should start over: Pattern1 -> Pattern2 -> ... -> Pattern16 -> Pattern1 -> ... .
How should this problem be solved in Angular?










share|improve this question

























  • Well, how far is your own code to this? I can't imagine that you got this task without having ever written any line of code yourself. This page is not supposed to do your homework, but to help you finding the errors in it.

    – Lynx 242
    Mar 29 '18 at 17:27














-1












-1








-1








I have a task to create 4 blinking divs in an Angular project. The colors come from an API in an array with 16 elements and each element is an array with 4 elements (string).



ColorPatterns[
Pattern1["Color1", "Color2", "Color3", "Color4"],
Pattern2["Color1", "Color2", "Color3", "Color4"],
...
Pattern16["Color1", "Color2", "Color3", "Color4"],
]


Color1 is for the first div, Color2 is for the second div and so on.
The sequence of 16 must change per 1 second and after the last element (Pattern16) the sequence should start over: Pattern1 -> Pattern2 -> ... -> Pattern16 -> Pattern1 -> ... .
How should this problem be solved in Angular?










share|improve this question
















I have a task to create 4 blinking divs in an Angular project. The colors come from an API in an array with 16 elements and each element is an array with 4 elements (string).



ColorPatterns[
Pattern1["Color1", "Color2", "Color3", "Color4"],
Pattern2["Color1", "Color2", "Color3", "Color4"],
...
Pattern16["Color1", "Color2", "Color3", "Color4"],
]


Color1 is for the first div, Color2 is for the second div and so on.
The sequence of 16 must change per 1 second and after the last element (Pattern16) the sequence should start over: Pattern1 -> Pattern2 -> ... -> Pattern16 -> Pattern1 -> ... .
How should this problem be solved in Angular?







css angular






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 2:32









Cœur

17.7k9106145




17.7k9106145










asked Mar 29 '18 at 15:01









xyzzxyzz

36




36













  • Well, how far is your own code to this? I can't imagine that you got this task without having ever written any line of code yourself. This page is not supposed to do your homework, but to help you finding the errors in it.

    – Lynx 242
    Mar 29 '18 at 17:27



















  • Well, how far is your own code to this? I can't imagine that you got this task without having ever written any line of code yourself. This page is not supposed to do your homework, but to help you finding the errors in it.

    – Lynx 242
    Mar 29 '18 at 17:27

















Well, how far is your own code to this? I can't imagine that you got this task without having ever written any line of code yourself. This page is not supposed to do your homework, but to help you finding the errors in it.

– Lynx 242
Mar 29 '18 at 17:27





Well, how far is your own code to this? I can't imagine that you got this task without having ever written any line of code yourself. This page is not supposed to do your homework, but to help you finding the errors in it.

– Lynx 242
Mar 29 '18 at 17:27












1 Answer
1






active

oldest

votes


















0














Use an Observable to do the timing stuff. If we can to it for one div then others can be repeated.



Observable.interval(1000) //emit every 1 sec with values = 0 then 1 them 2 ..
.map(value=>ColorPaterns[value%16][0]) // 0 for 1st color
.subscribe((firstColor)=>{
// set 1st div color here
})





share|improve this answer
























  • Awesome! This worked as expected. Thanks a lot!

    – xyzz
    Apr 3 '18 at 14:37











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49559345%2fblinking-color-sequence-in-angular%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Use an Observable to do the timing stuff. If we can to it for one div then others can be repeated.



Observable.interval(1000) //emit every 1 sec with values = 0 then 1 them 2 ..
.map(value=>ColorPaterns[value%16][0]) // 0 for 1st color
.subscribe((firstColor)=>{
// set 1st div color here
})





share|improve this answer
























  • Awesome! This worked as expected. Thanks a lot!

    – xyzz
    Apr 3 '18 at 14:37
















0














Use an Observable to do the timing stuff. If we can to it for one div then others can be repeated.



Observable.interval(1000) //emit every 1 sec with values = 0 then 1 them 2 ..
.map(value=>ColorPaterns[value%16][0]) // 0 for 1st color
.subscribe((firstColor)=>{
// set 1st div color here
})





share|improve this answer
























  • Awesome! This worked as expected. Thanks a lot!

    – xyzz
    Apr 3 '18 at 14:37














0












0








0







Use an Observable to do the timing stuff. If we can to it for one div then others can be repeated.



Observable.interval(1000) //emit every 1 sec with values = 0 then 1 them 2 ..
.map(value=>ColorPaterns[value%16][0]) // 0 for 1st color
.subscribe((firstColor)=>{
// set 1st div color here
})





share|improve this answer













Use an Observable to do the timing stuff. If we can to it for one div then others can be repeated.



Observable.interval(1000) //emit every 1 sec with values = 0 then 1 them 2 ..
.map(value=>ColorPaterns[value%16][0]) // 0 for 1st color
.subscribe((firstColor)=>{
// set 1st div color here
})






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 29 '18 at 17:33









amit77309amit77309

3,62931118




3,62931118













  • Awesome! This worked as expected. Thanks a lot!

    – xyzz
    Apr 3 '18 at 14:37



















  • Awesome! This worked as expected. Thanks a lot!

    – xyzz
    Apr 3 '18 at 14:37

















Awesome! This worked as expected. Thanks a lot!

– xyzz
Apr 3 '18 at 14:37





Awesome! This worked as expected. Thanks a lot!

– xyzz
Apr 3 '18 at 14:37


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49559345%2fblinking-color-sequence-in-angular%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga