How to get badge value of button in Angular JS2019 Community Moderator ElectionWhen to use ng-attr?Badges For Buttons using html and CSSWhat are valid values for the id attribute in HTML?How to horizontally center a <div>?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How can I know which radio button is selected via jQuery?How do I give text or an image a transparent background using CSS?How to disable text selection highlighting?How to check whether a checkbox is checked in jQuery?How to make a div 100% height of the browser window?How to disable resizable property of textarea?How do I vertically center text with CSS?

Single word request: Harming the benefactor

Fourth person (in Slavey language)

How are such low op-amp input currents possible?

Algorithm to convert a fixed-length string to the smallest possible collision-free representation?

How strictly should I take "Candidates must be local"?

Things to avoid when using voltage regulators?

Rejected in 4th interview round citing insufficient years of experience

Are babies of evil humanoid species inherently evil?

Do items de-spawn in Diablo?

Best approach to update all entries in a list that is paginated?

Why the color red for the Republican Party

How did Alan Turing break the enigma code using the hint given by the lady in the bar?

Subset counting for even numbers

Should QA ask requirements to developers?

Why does the negative sign arise in this thermodynamic relation?

They call me Inspector Morse

BitNot does not flip bits in the way I expected

Low budget alien movie about the Earth being cooked

Good allowance savings plan?

Is it true that real estate prices mainly go up?

2×2×2 rubik's cube corner is twisted!

A three room house but a three headED dog

Could you please stop shuffling the deck and play already?

What does a stand alone "T" index value do?



How to get badge value of button in Angular JS



2019 Community Moderator ElectionWhen to use ng-attr?Badges For Buttons using html and CSSWhat are valid values for the id attribute in HTML?How to horizontally center a <div>?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How can I know which radio button is selected via jQuery?How do I give text or an image a transparent background using CSS?How to disable text selection highlighting?How to check whether a checkbox is checked in jQuery?How to make a div 100% height of the browser window?How to disable resizable property of textarea?How do I vertically center text with CSS?










0















I want badge value of a Button, this represent badge is data-text-as-pseudo-element i am new to angular so how do i get it ?




<style
type="text/css">[data-text-as-pseudo-element]::before content: attr(data-text-as-pseudo-element);
</style>


<button role="tab" title="Chats" tabindex="0" aria-label="Chats, 1
unread notification." aria-selected="true" style="position: relative;
display: flex; flex-direction: column; flex-grow: 0; flex-shrink: 0;
overflow: hidden; align-items: center; justify-content: center;
background-color: transparent; border-color: transparent; text-align:
left; border-width: 0px; width: 80px; padding-top: 2px; height: 50px;
cursor: pointer; border-style: solid;">
<div role="none"
style="position: relative; display: flex; flex-direction: column;
flex-grow: 0; flex-shrink: 0; overflow: hidden; align-items: center;
justify-content: center; width: 80px; height: 50px;">
<div
aria-hidden="true" data-text-as-pseudo-element="" style="position:
relative; display: inline; flex-grow: 0; flex-shrink: 0; overflow:
hidden; white-space: pre-wrap; overflow-wrap: break-word; height:
20px; font-size: 20px; color: rgb(0, 120, 212); background-color:
rgba(0, 0, 0, 0); font-family: SkypeAssets-Light; padding: 0px;
cursor: inherit;"></div><div data-text-as-pseudo-element="Chats"
style="position: relative; display: inline; flex-grow: 0;
flex-shrink: 0; overflow: hidden; white-space: pre; text-overflow:
ellipsis; font-size: 10px; color: rgb(0, 120, 212); font-family:
&quot;SF Regular&quot;, &quot;Segoe System UI Regular&quot;,
&quot;Segoe UI Regular&quot;, sans-serif; font-weight: 400;
text-align: center; margin-top: 2px; align-self: stretch; cursor:
inherit;"></div><div role="none" aria-hidden="true" style="position:
absolute; display: flex; flex-direction: column; flex-grow: 0;
flex-shrink: 0; overflow: visible; align-items: center; height: 24px;
width: 30px; top: 0px; right: 12px; justify-content: center;">
<div
role="none" style="position: relative; display: flex; flex-direction:
column; flex-grow: 0; flex-shrink: 0; overflow: hidden; align-items:
center; justify-content: center; height: 20px; min-width: 20px;
border-radius: 10px; background-color: rgb(244, 67, 54);
padding-left: 4px; padding-right: 4px; width: 20px; border-color:
rgb(240, 244, 248); border-width: 2px; border-style: solid;">
<div
data-text-as-pseudo-element="1" style="position: relative; display:
inline; flex-grow: 0; flex-shrink: 0; overflow: hidden; white-space:
pre; text-overflow: ellipsis; color: rgb(255, 255, 255); font-size:
10px; line-height: 10px; text-align: center; background-color:
rgba(0, 0, 0, 0); font-family: &quot;SF Bold&quot;, &quot;Segoe
System UI Bold&quot;, &quot;Segoe UI Bold&quot;, sans-serif;
font-weight: 400; cursor: inherit;">
</div>
</div>
</div>
</div>
</button>



this



Any suggestion ?



Thanks in Advance !!










share|improve this question
























  • You can take this answer as a starting point, designing the button with badge itself: stackoverflow.com/a/27016902/1854269 . Then you can use ng-class directive to dynamically assign a class to the button, depends on whether there are some notifcations or not. Unfortunately, the example above is not workng properly in IE 11, if this is important for you.

    – CodeMonkey
    Mar 7 at 8:11












  • @CodeMonkey ok but how do i get the value of chats count ?

    – jarvis12
    Mar 7 at 8:14















0















I want badge value of a Button, this represent badge is data-text-as-pseudo-element i am new to angular so how do i get it ?




<style
type="text/css">[data-text-as-pseudo-element]::before content: attr(data-text-as-pseudo-element);
</style>


<button role="tab" title="Chats" tabindex="0" aria-label="Chats, 1
unread notification." aria-selected="true" style="position: relative;
display: flex; flex-direction: column; flex-grow: 0; flex-shrink: 0;
overflow: hidden; align-items: center; justify-content: center;
background-color: transparent; border-color: transparent; text-align:
left; border-width: 0px; width: 80px; padding-top: 2px; height: 50px;
cursor: pointer; border-style: solid;">
<div role="none"
style="position: relative; display: flex; flex-direction: column;
flex-grow: 0; flex-shrink: 0; overflow: hidden; align-items: center;
justify-content: center; width: 80px; height: 50px;">
<div
aria-hidden="true" data-text-as-pseudo-element="" style="position:
relative; display: inline; flex-grow: 0; flex-shrink: 0; overflow:
hidden; white-space: pre-wrap; overflow-wrap: break-word; height:
20px; font-size: 20px; color: rgb(0, 120, 212); background-color:
rgba(0, 0, 0, 0); font-family: SkypeAssets-Light; padding: 0px;
cursor: inherit;"></div><div data-text-as-pseudo-element="Chats"
style="position: relative; display: inline; flex-grow: 0;
flex-shrink: 0; overflow: hidden; white-space: pre; text-overflow:
ellipsis; font-size: 10px; color: rgb(0, 120, 212); font-family:
&quot;SF Regular&quot;, &quot;Segoe System UI Regular&quot;,
&quot;Segoe UI Regular&quot;, sans-serif; font-weight: 400;
text-align: center; margin-top: 2px; align-self: stretch; cursor:
inherit;"></div><div role="none" aria-hidden="true" style="position:
absolute; display: flex; flex-direction: column; flex-grow: 0;
flex-shrink: 0; overflow: visible; align-items: center; height: 24px;
width: 30px; top: 0px; right: 12px; justify-content: center;">
<div
role="none" style="position: relative; display: flex; flex-direction:
column; flex-grow: 0; flex-shrink: 0; overflow: hidden; align-items:
center; justify-content: center; height: 20px; min-width: 20px;
border-radius: 10px; background-color: rgb(244, 67, 54);
padding-left: 4px; padding-right: 4px; width: 20px; border-color:
rgb(240, 244, 248); border-width: 2px; border-style: solid;">
<div
data-text-as-pseudo-element="1" style="position: relative; display:
inline; flex-grow: 0; flex-shrink: 0; overflow: hidden; white-space:
pre; text-overflow: ellipsis; color: rgb(255, 255, 255); font-size:
10px; line-height: 10px; text-align: center; background-color:
rgba(0, 0, 0, 0); font-family: &quot;SF Bold&quot;, &quot;Segoe
System UI Bold&quot;, &quot;Segoe UI Bold&quot;, sans-serif;
font-weight: 400; cursor: inherit;">
</div>
</div>
</div>
</div>
</button>



this



Any suggestion ?



Thanks in Advance !!










share|improve this question
























  • You can take this answer as a starting point, designing the button with badge itself: stackoverflow.com/a/27016902/1854269 . Then you can use ng-class directive to dynamically assign a class to the button, depends on whether there are some notifcations or not. Unfortunately, the example above is not workng properly in IE 11, if this is important for you.

    – CodeMonkey
    Mar 7 at 8:11












  • @CodeMonkey ok but how do i get the value of chats count ?

    – jarvis12
    Mar 7 at 8:14













0












0








0








I want badge value of a Button, this represent badge is data-text-as-pseudo-element i am new to angular so how do i get it ?




<style
type="text/css">[data-text-as-pseudo-element]::before content: attr(data-text-as-pseudo-element);
</style>


<button role="tab" title="Chats" tabindex="0" aria-label="Chats, 1
unread notification." aria-selected="true" style="position: relative;
display: flex; flex-direction: column; flex-grow: 0; flex-shrink: 0;
overflow: hidden; align-items: center; justify-content: center;
background-color: transparent; border-color: transparent; text-align:
left; border-width: 0px; width: 80px; padding-top: 2px; height: 50px;
cursor: pointer; border-style: solid;">
<div role="none"
style="position: relative; display: flex; flex-direction: column;
flex-grow: 0; flex-shrink: 0; overflow: hidden; align-items: center;
justify-content: center; width: 80px; height: 50px;">
<div
aria-hidden="true" data-text-as-pseudo-element="" style="position:
relative; display: inline; flex-grow: 0; flex-shrink: 0; overflow:
hidden; white-space: pre-wrap; overflow-wrap: break-word; height:
20px; font-size: 20px; color: rgb(0, 120, 212); background-color:
rgba(0, 0, 0, 0); font-family: SkypeAssets-Light; padding: 0px;
cursor: inherit;"></div><div data-text-as-pseudo-element="Chats"
style="position: relative; display: inline; flex-grow: 0;
flex-shrink: 0; overflow: hidden; white-space: pre; text-overflow:
ellipsis; font-size: 10px; color: rgb(0, 120, 212); font-family:
&quot;SF Regular&quot;, &quot;Segoe System UI Regular&quot;,
&quot;Segoe UI Regular&quot;, sans-serif; font-weight: 400;
text-align: center; margin-top: 2px; align-self: stretch; cursor:
inherit;"></div><div role="none" aria-hidden="true" style="position:
absolute; display: flex; flex-direction: column; flex-grow: 0;
flex-shrink: 0; overflow: visible; align-items: center; height: 24px;
width: 30px; top: 0px; right: 12px; justify-content: center;">
<div
role="none" style="position: relative; display: flex; flex-direction:
column; flex-grow: 0; flex-shrink: 0; overflow: hidden; align-items:
center; justify-content: center; height: 20px; min-width: 20px;
border-radius: 10px; background-color: rgb(244, 67, 54);
padding-left: 4px; padding-right: 4px; width: 20px; border-color:
rgb(240, 244, 248); border-width: 2px; border-style: solid;">
<div
data-text-as-pseudo-element="1" style="position: relative; display:
inline; flex-grow: 0; flex-shrink: 0; overflow: hidden; white-space:
pre; text-overflow: ellipsis; color: rgb(255, 255, 255); font-size:
10px; line-height: 10px; text-align: center; background-color:
rgba(0, 0, 0, 0); font-family: &quot;SF Bold&quot;, &quot;Segoe
System UI Bold&quot;, &quot;Segoe UI Bold&quot;, sans-serif;
font-weight: 400; cursor: inherit;">
</div>
</div>
</div>
</div>
</button>



this



Any suggestion ?



Thanks in Advance !!










share|improve this question
















I want badge value of a Button, this represent badge is data-text-as-pseudo-element i am new to angular so how do i get it ?




<style
type="text/css">[data-text-as-pseudo-element]::before content: attr(data-text-as-pseudo-element);
</style>


<button role="tab" title="Chats" tabindex="0" aria-label="Chats, 1
unread notification." aria-selected="true" style="position: relative;
display: flex; flex-direction: column; flex-grow: 0; flex-shrink: 0;
overflow: hidden; align-items: center; justify-content: center;
background-color: transparent; border-color: transparent; text-align:
left; border-width: 0px; width: 80px; padding-top: 2px; height: 50px;
cursor: pointer; border-style: solid;">
<div role="none"
style="position: relative; display: flex; flex-direction: column;
flex-grow: 0; flex-shrink: 0; overflow: hidden; align-items: center;
justify-content: center; width: 80px; height: 50px;">
<div
aria-hidden="true" data-text-as-pseudo-element="" style="position:
relative; display: inline; flex-grow: 0; flex-shrink: 0; overflow:
hidden; white-space: pre-wrap; overflow-wrap: break-word; height:
20px; font-size: 20px; color: rgb(0, 120, 212); background-color:
rgba(0, 0, 0, 0); font-family: SkypeAssets-Light; padding: 0px;
cursor: inherit;"></div><div data-text-as-pseudo-element="Chats"
style="position: relative; display: inline; flex-grow: 0;
flex-shrink: 0; overflow: hidden; white-space: pre; text-overflow:
ellipsis; font-size: 10px; color: rgb(0, 120, 212); font-family:
&quot;SF Regular&quot;, &quot;Segoe System UI Regular&quot;,
&quot;Segoe UI Regular&quot;, sans-serif; font-weight: 400;
text-align: center; margin-top: 2px; align-self: stretch; cursor:
inherit;"></div><div role="none" aria-hidden="true" style="position:
absolute; display: flex; flex-direction: column; flex-grow: 0;
flex-shrink: 0; overflow: visible; align-items: center; height: 24px;
width: 30px; top: 0px; right: 12px; justify-content: center;">
<div
role="none" style="position: relative; display: flex; flex-direction:
column; flex-grow: 0; flex-shrink: 0; overflow: hidden; align-items:
center; justify-content: center; height: 20px; min-width: 20px;
border-radius: 10px; background-color: rgb(244, 67, 54);
padding-left: 4px; padding-right: 4px; width: 20px; border-color:
rgb(240, 244, 248); border-width: 2px; border-style: solid;">
<div
data-text-as-pseudo-element="1" style="position: relative; display:
inline; flex-grow: 0; flex-shrink: 0; overflow: hidden; white-space:
pre; text-overflow: ellipsis; color: rgb(255, 255, 255); font-size:
10px; line-height: 10px; text-align: center; background-color:
rgba(0, 0, 0, 0); font-family: &quot;SF Bold&quot;, &quot;Segoe
System UI Bold&quot;, &quot;Segoe UI Bold&quot;, sans-serif;
font-weight: 400; cursor: inherit;">
</div>
</div>
</div>
</div>
</button>



this



Any suggestion ?



Thanks in Advance !!







html css angularjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 10:10







jarvis12

















asked Mar 7 at 7:55









jarvis12jarvis12

846




846












  • You can take this answer as a starting point, designing the button with badge itself: stackoverflow.com/a/27016902/1854269 . Then you can use ng-class directive to dynamically assign a class to the button, depends on whether there are some notifcations or not. Unfortunately, the example above is not workng properly in IE 11, if this is important for you.

    – CodeMonkey
    Mar 7 at 8:11












  • @CodeMonkey ok but how do i get the value of chats count ?

    – jarvis12
    Mar 7 at 8:14

















  • You can take this answer as a starting point, designing the button with badge itself: stackoverflow.com/a/27016902/1854269 . Then you can use ng-class directive to dynamically assign a class to the button, depends on whether there are some notifcations or not. Unfortunately, the example above is not workng properly in IE 11, if this is important for you.

    – CodeMonkey
    Mar 7 at 8:11












  • @CodeMonkey ok but how do i get the value of chats count ?

    – jarvis12
    Mar 7 at 8:14
















You can take this answer as a starting point, designing the button with badge itself: stackoverflow.com/a/27016902/1854269 . Then you can use ng-class directive to dynamically assign a class to the button, depends on whether there are some notifcations or not. Unfortunately, the example above is not workng properly in IE 11, if this is important for you.

– CodeMonkey
Mar 7 at 8:11






You can take this answer as a starting point, designing the button with badge itself: stackoverflow.com/a/27016902/1854269 . Then you can use ng-class directive to dynamically assign a class to the button, depends on whether there are some notifcations or not. Unfortunately, the example above is not workng properly in IE 11, if this is important for you.

– CodeMonkey
Mar 7 at 8:11














@CodeMonkey ok but how do i get the value of chats count ?

– jarvis12
Mar 7 at 8:14





@CodeMonkey ok but how do i get the value of chats count ?

– jarvis12
Mar 7 at 8:14












1 Answer
1






active

oldest

votes


















0














I have prepared a working example. Unfortunately, this code is not working in IE11. To make it work in IE11, CSS has to be adjusted.



Example is based on solution from here:
Link



The main point is that from example over the link: you indicate, how many notifcations do you have over the attribute 'data-count':



<button class="notification-button" data-count="5"></button>


To make it dynamic in angularjs, you have to bind this attribute with scope varialbe using ng-attr-* directive



<button class="notification-button" ng-attr-data-count="counter"></button>


AngularJS docs gn-attr-*



When to use ng-attr?






angular
.module('myApp', [])
.controller('myCtrl', myCtrl);

myCtrl.inject = ['$scope'];

function myCtrl($scope)
$scope.counter = 0;

$scope.increment = function()
$scope.counter++;


.notification-button 
background: linear-gradient(to bottom, rgba(37, 130, 188, 1) 0%, rgba(41, 137, 216, 1) 32%, rgba(41, 137, 216, 1) 42%, rgba(175, 224, 234, 1) 100%);
width: 60px;
height: 60px;
border-radius: 10px;
border: none;
margin-top: 40px;
margin-left: 40px;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);


.notification-button:before
content: attr(data-count);
width: 18px;
height: 18px;
line-height: 18px;
text-align: center;
display: block;
border-radius: 50%;
background: rgb(67, 151, 232);
border: 1px solid #FFF;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
color: #FFF;
position: absolute;
top: -7px;
left: -7px;


.notification-button.badge-top-right:before
left: auto;
right: -7px;


.notification-button.badge-bottom-right:before
left: auto;
top: auto;
right: -7px;
bottom: -7px;


.notification-button.badge-bottom-left:before
top: auto;
bottom: -7px;

<!DOCTYPE html>
<html lang="en" ng-app="myApp" ng-controller="myCtrl">

<head>
<meta charset="UTF-8">
<title>Test</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
</head>

<body>

<button ng-click="increment();">Increment</button>

<div>
counter
</div>

<button class="notification-button" ng-attr-data-count="counter"></button>


</body>

</html>








share|improve this answer

























  • i don't want to create a button with badge i just want the how to get chat badge value 1 from the snippet that i provided in question.

    – jarvis12
    Mar 7 at 9:38











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%2f55038698%2fhow-to-get-badge-value-of-button-in-angular-js%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














I have prepared a working example. Unfortunately, this code is not working in IE11. To make it work in IE11, CSS has to be adjusted.



Example is based on solution from here:
Link



The main point is that from example over the link: you indicate, how many notifcations do you have over the attribute 'data-count':



<button class="notification-button" data-count="5"></button>


To make it dynamic in angularjs, you have to bind this attribute with scope varialbe using ng-attr-* directive



<button class="notification-button" ng-attr-data-count="counter"></button>


AngularJS docs gn-attr-*



When to use ng-attr?






angular
.module('myApp', [])
.controller('myCtrl', myCtrl);

myCtrl.inject = ['$scope'];

function myCtrl($scope)
$scope.counter = 0;

$scope.increment = function()
$scope.counter++;


.notification-button 
background: linear-gradient(to bottom, rgba(37, 130, 188, 1) 0%, rgba(41, 137, 216, 1) 32%, rgba(41, 137, 216, 1) 42%, rgba(175, 224, 234, 1) 100%);
width: 60px;
height: 60px;
border-radius: 10px;
border: none;
margin-top: 40px;
margin-left: 40px;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);


.notification-button:before
content: attr(data-count);
width: 18px;
height: 18px;
line-height: 18px;
text-align: center;
display: block;
border-radius: 50%;
background: rgb(67, 151, 232);
border: 1px solid #FFF;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
color: #FFF;
position: absolute;
top: -7px;
left: -7px;


.notification-button.badge-top-right:before
left: auto;
right: -7px;


.notification-button.badge-bottom-right:before
left: auto;
top: auto;
right: -7px;
bottom: -7px;


.notification-button.badge-bottom-left:before
top: auto;
bottom: -7px;

<!DOCTYPE html>
<html lang="en" ng-app="myApp" ng-controller="myCtrl">

<head>
<meta charset="UTF-8">
<title>Test</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
</head>

<body>

<button ng-click="increment();">Increment</button>

<div>
counter
</div>

<button class="notification-button" ng-attr-data-count="counter"></button>


</body>

</html>








share|improve this answer

























  • i don't want to create a button with badge i just want the how to get chat badge value 1 from the snippet that i provided in question.

    – jarvis12
    Mar 7 at 9:38
















0














I have prepared a working example. Unfortunately, this code is not working in IE11. To make it work in IE11, CSS has to be adjusted.



Example is based on solution from here:
Link



The main point is that from example over the link: you indicate, how many notifcations do you have over the attribute 'data-count':



<button class="notification-button" data-count="5"></button>


To make it dynamic in angularjs, you have to bind this attribute with scope varialbe using ng-attr-* directive



<button class="notification-button" ng-attr-data-count="counter"></button>


AngularJS docs gn-attr-*



When to use ng-attr?






angular
.module('myApp', [])
.controller('myCtrl', myCtrl);

myCtrl.inject = ['$scope'];

function myCtrl($scope)
$scope.counter = 0;

$scope.increment = function()
$scope.counter++;


.notification-button 
background: linear-gradient(to bottom, rgba(37, 130, 188, 1) 0%, rgba(41, 137, 216, 1) 32%, rgba(41, 137, 216, 1) 42%, rgba(175, 224, 234, 1) 100%);
width: 60px;
height: 60px;
border-radius: 10px;
border: none;
margin-top: 40px;
margin-left: 40px;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);


.notification-button:before
content: attr(data-count);
width: 18px;
height: 18px;
line-height: 18px;
text-align: center;
display: block;
border-radius: 50%;
background: rgb(67, 151, 232);
border: 1px solid #FFF;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
color: #FFF;
position: absolute;
top: -7px;
left: -7px;


.notification-button.badge-top-right:before
left: auto;
right: -7px;


.notification-button.badge-bottom-right:before
left: auto;
top: auto;
right: -7px;
bottom: -7px;


.notification-button.badge-bottom-left:before
top: auto;
bottom: -7px;

<!DOCTYPE html>
<html lang="en" ng-app="myApp" ng-controller="myCtrl">

<head>
<meta charset="UTF-8">
<title>Test</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
</head>

<body>

<button ng-click="increment();">Increment</button>

<div>
counter
</div>

<button class="notification-button" ng-attr-data-count="counter"></button>


</body>

</html>








share|improve this answer

























  • i don't want to create a button with badge i just want the how to get chat badge value 1 from the snippet that i provided in question.

    – jarvis12
    Mar 7 at 9:38














0












0








0







I have prepared a working example. Unfortunately, this code is not working in IE11. To make it work in IE11, CSS has to be adjusted.



Example is based on solution from here:
Link



The main point is that from example over the link: you indicate, how many notifcations do you have over the attribute 'data-count':



<button class="notification-button" data-count="5"></button>


To make it dynamic in angularjs, you have to bind this attribute with scope varialbe using ng-attr-* directive



<button class="notification-button" ng-attr-data-count="counter"></button>


AngularJS docs gn-attr-*



When to use ng-attr?






angular
.module('myApp', [])
.controller('myCtrl', myCtrl);

myCtrl.inject = ['$scope'];

function myCtrl($scope)
$scope.counter = 0;

$scope.increment = function()
$scope.counter++;


.notification-button 
background: linear-gradient(to bottom, rgba(37, 130, 188, 1) 0%, rgba(41, 137, 216, 1) 32%, rgba(41, 137, 216, 1) 42%, rgba(175, 224, 234, 1) 100%);
width: 60px;
height: 60px;
border-radius: 10px;
border: none;
margin-top: 40px;
margin-left: 40px;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);


.notification-button:before
content: attr(data-count);
width: 18px;
height: 18px;
line-height: 18px;
text-align: center;
display: block;
border-radius: 50%;
background: rgb(67, 151, 232);
border: 1px solid #FFF;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
color: #FFF;
position: absolute;
top: -7px;
left: -7px;


.notification-button.badge-top-right:before
left: auto;
right: -7px;


.notification-button.badge-bottom-right:before
left: auto;
top: auto;
right: -7px;
bottom: -7px;


.notification-button.badge-bottom-left:before
top: auto;
bottom: -7px;

<!DOCTYPE html>
<html lang="en" ng-app="myApp" ng-controller="myCtrl">

<head>
<meta charset="UTF-8">
<title>Test</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
</head>

<body>

<button ng-click="increment();">Increment</button>

<div>
counter
</div>

<button class="notification-button" ng-attr-data-count="counter"></button>


</body>

</html>








share|improve this answer















I have prepared a working example. Unfortunately, this code is not working in IE11. To make it work in IE11, CSS has to be adjusted.



Example is based on solution from here:
Link



The main point is that from example over the link: you indicate, how many notifcations do you have over the attribute 'data-count':



<button class="notification-button" data-count="5"></button>


To make it dynamic in angularjs, you have to bind this attribute with scope varialbe using ng-attr-* directive



<button class="notification-button" ng-attr-data-count="counter"></button>


AngularJS docs gn-attr-*



When to use ng-attr?






angular
.module('myApp', [])
.controller('myCtrl', myCtrl);

myCtrl.inject = ['$scope'];

function myCtrl($scope)
$scope.counter = 0;

$scope.increment = function()
$scope.counter++;


.notification-button 
background: linear-gradient(to bottom, rgba(37, 130, 188, 1) 0%, rgba(41, 137, 216, 1) 32%, rgba(41, 137, 216, 1) 42%, rgba(175, 224, 234, 1) 100%);
width: 60px;
height: 60px;
border-radius: 10px;
border: none;
margin-top: 40px;
margin-left: 40px;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);


.notification-button:before
content: attr(data-count);
width: 18px;
height: 18px;
line-height: 18px;
text-align: center;
display: block;
border-radius: 50%;
background: rgb(67, 151, 232);
border: 1px solid #FFF;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
color: #FFF;
position: absolute;
top: -7px;
left: -7px;


.notification-button.badge-top-right:before
left: auto;
right: -7px;


.notification-button.badge-bottom-right:before
left: auto;
top: auto;
right: -7px;
bottom: -7px;


.notification-button.badge-bottom-left:before
top: auto;
bottom: -7px;

<!DOCTYPE html>
<html lang="en" ng-app="myApp" ng-controller="myCtrl">

<head>
<meta charset="UTF-8">
<title>Test</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
</head>

<body>

<button ng-click="increment();">Increment</button>

<div>
counter
</div>

<button class="notification-button" ng-attr-data-count="counter"></button>


</body>

</html>








angular
.module('myApp', [])
.controller('myCtrl', myCtrl);

myCtrl.inject = ['$scope'];

function myCtrl($scope)
$scope.counter = 0;

$scope.increment = function()
$scope.counter++;


.notification-button 
background: linear-gradient(to bottom, rgba(37, 130, 188, 1) 0%, rgba(41, 137, 216, 1) 32%, rgba(41, 137, 216, 1) 42%, rgba(175, 224, 234, 1) 100%);
width: 60px;
height: 60px;
border-radius: 10px;
border: none;
margin-top: 40px;
margin-left: 40px;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);


.notification-button:before
content: attr(data-count);
width: 18px;
height: 18px;
line-height: 18px;
text-align: center;
display: block;
border-radius: 50%;
background: rgb(67, 151, 232);
border: 1px solid #FFF;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
color: #FFF;
position: absolute;
top: -7px;
left: -7px;


.notification-button.badge-top-right:before
left: auto;
right: -7px;


.notification-button.badge-bottom-right:before
left: auto;
top: auto;
right: -7px;
bottom: -7px;


.notification-button.badge-bottom-left:before
top: auto;
bottom: -7px;

<!DOCTYPE html>
<html lang="en" ng-app="myApp" ng-controller="myCtrl">

<head>
<meta charset="UTF-8">
<title>Test</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
</head>

<body>

<button ng-click="increment();">Increment</button>

<div>
counter
</div>

<button class="notification-button" ng-attr-data-count="counter"></button>


</body>

</html>





angular
.module('myApp', [])
.controller('myCtrl', myCtrl);

myCtrl.inject = ['$scope'];

function myCtrl($scope)
$scope.counter = 0;

$scope.increment = function()
$scope.counter++;


.notification-button 
background: linear-gradient(to bottom, rgba(37, 130, 188, 1) 0%, rgba(41, 137, 216, 1) 32%, rgba(41, 137, 216, 1) 42%, rgba(175, 224, 234, 1) 100%);
width: 60px;
height: 60px;
border-radius: 10px;
border: none;
margin-top: 40px;
margin-left: 40px;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);


.notification-button:before
content: attr(data-count);
width: 18px;
height: 18px;
line-height: 18px;
text-align: center;
display: block;
border-radius: 50%;
background: rgb(67, 151, 232);
border: 1px solid #FFF;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
color: #FFF;
position: absolute;
top: -7px;
left: -7px;


.notification-button.badge-top-right:before
left: auto;
right: -7px;


.notification-button.badge-bottom-right:before
left: auto;
top: auto;
right: -7px;
bottom: -7px;


.notification-button.badge-bottom-left:before
top: auto;
bottom: -7px;

<!DOCTYPE html>
<html lang="en" ng-app="myApp" ng-controller="myCtrl">

<head>
<meta charset="UTF-8">
<title>Test</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
</head>

<body>

<button ng-click="increment();">Increment</button>

<div>
counter
</div>

<button class="notification-button" ng-attr-data-count="counter"></button>


</body>

</html>






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 7 at 8:48

























answered Mar 7 at 8:31









CodeMonkeyCodeMonkey

106316




106316












  • i don't want to create a button with badge i just want the how to get chat badge value 1 from the snippet that i provided in question.

    – jarvis12
    Mar 7 at 9:38


















  • i don't want to create a button with badge i just want the how to get chat badge value 1 from the snippet that i provided in question.

    – jarvis12
    Mar 7 at 9:38

















i don't want to create a button with badge i just want the how to get chat badge value 1 from the snippet that i provided in question.

– jarvis12
Mar 7 at 9:38






i don't want to create a button with badge i just want the how to get chat badge value 1 from the snippet that i provided in question.

– jarvis12
Mar 7 at 9:38




















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%2f55038698%2fhow-to-get-badge-value-of-button-in-angular-js%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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page