AngularJS supports .attr(), .removeAttr() jQuery functionality. Here in below examples we can see how to set attribute and remove attribute of an element.
Angular2 : If you are looking for Angular2 solution, please click here

Read or Assign value to attribute :

By using expressions, attribute values can be changed. Observe below code
....
<input ng-model="atribut"/>
....
<div myattr="{{atribut}}" id="divID">
  Attribute DIV <b>{{atribut}}</b>
</div>
<script>
function myCtrl($scope) {
    $scope.atribut="val 1";
}
</script>

Steps to read attribute value of an elemnt :

  1. Get angular element of html element
  2. Use .attr('attribute name') method to read the attribute value
var myEl = angular.element( document.querySelector( '#divID' ) );
alert(myEl.attr('myattr'));

Steps to set attribute value of an element :

  1. Get angular element
  2. Use .attr('attribute name', 'attribute value') method to set the attribute value
var myEl = angular.element( document.querySelector( '#divID' ) );
myEl.attr('myattr',"attr val");

Steps to remove attribute of an element :

  1. Get angular element
  2. Use .attr('attribute name', 'attribute value') method to set the attribute value
var myEl = angular.element( document.querySelector( '#divID' ) );
myEl.removeAttr('myattr');

27 comments:

  1. I need to set focus on a textbox when a hyperlink is clicked. I tried angular.element("#id").focus(), and $("#id").focus(), but nothing works. Is there an easier way to handle focus in angular?

    ReplyDelete
    Replies
    1. will that hyperlink redirects to new page or stays in same page ( with only # tag change) ?

      Delete
  2. does setting attribute work with angular version 1.5.0

    ReplyDelete
  3. what if the attribute is an object?

    ReplyDelete
  4. In the title it says "Set Attribute or Remove Attribute using AngularJS". Are you actually showing that?

    ReplyDelete
  5. do you have any idea on dynamic setting of attribute using angular JS,
    In jquery, there is prop method by which we can set attribute dynamicaaly

    ReplyDelete
  6. Sehar News is a wide area that envelops Pakistan News, International News, Sports News, Arts and
    Entertainment News, Science and Technology, Business News, Education News and Today's Columns.
    The perusers can snatch most recent Urdu News dependent on different political and get-together
    occurring in the nation. Sehar News covers the most recent and up and coming news features, top
    stories from different backgrounds and carries it to the viewers. , Visit Daily http://www.seharnews.pk
    For latest updates and News,Thanks every one.

    ReplyDelete
  7. Tech Gadgets reviews and latest Tech and Gadgets news updates, trends, explore the facts, research, and analysis covering the digital world.
    You will see Some Tech reviews below,

    lg bluetooth headset : You will also wish to keep design and assorted features in mind. The most essential part of the design here is the buttonsof lg bluetooth headset .

    Fastest Car in the World : is a lot more than the usual number. Nevertheless, non-enthusiasts and fans alike can’t resist the impulse to brag or estimate according to specifications. Fastest Car in the World click here to know more.

    samsung galaxy gear : Samsung will undoubtedly put a great deal of time and even more cash into courting developers It is looking for partners and will allow developers to try out
    different sensors and software. It is preparing two variants as they launched last year. samsung galaxy gear is very use full click to know more.

    samsung fridge : Samsung plans to supply family-oriented applications like health care programs and digital picture frames along with games It should stick with what they know and they
    do not know how to produce a quality refrigerator that is worth what we paid. samsung fridge is very usefull and nice product. clickcamera best for travel: Nikon D850: Camera It may be costly, but if you’re trying to find the very best camera you can purchase at this time, then Nikon’s gorgeous DX50 DSLR will
    probably mark each box. The packaging is in a vibrant 45.4-megapixel full-frame detector, the picture quality is simply wonderful. However, this is just half the story. Because of a complex 153-point AF system along with a brst rate of 9 frames per minute. camera best specification. click here to know more.

    visit https://techgadgets.expert/ this site to know more.

    ReplyDelete
  8. PhenQ Reviews 2019 – WHAT IS PhenQ ?


    How to use PhenQ ?This is a powerful slimming formula made by combining the multiple weight loss
    benefits of variousPhenQ ingredients. All these are conveniently contained in
    one pill. It helps you get the kind of body that you need. The ingredients of
    the pill are from natural sources so you don’t have to worry much about the side
    effects that come with other types of dieting pills.Is_PhenQ_safe ? yes this is completly safe.
    Where to buy PhenQ ? you can order online.PhenQ Scam ? this medicine is not scam at all.


    Watch this PhenQ Reviews to know more.
    Know about PhenQ Scam from here.
    know Is PhenQ safe for health.
    you don`t know How to use PhenQ check this site

    wanna buy phenq check this site and know Where to buyPhenQ and how to use.

    check the PhenQ ingredients to know more.

    what is PhenQ check this site.

    ReplyDelete
  9. Weed Supermarket.
    Cannabis oil for sale, buy cannabis oil online, where to buy cannabis oil, cannabis oil for sale, buy cannabis oil online,
    cannabis oil for sale UK, cannabis oil for sale, where to buy cannabis oil UKBuy cbd oil, buying marijuana edibles online legal,
    online marijuana sales, buy cbd oil UK, best cbd oil UK, cheap cbd oil UK, pure thc for sale, cbd oil wholesale UK, cbd oil online buy UK
    Cbd flower for sale uk, cbd buds wholesale uk, cbd flower for sale uk, buy hemp buds uk, cheap cbd, flower uk, buy cbd buds online uk,
    cbd flowers buds uk, cbd buds for sale, cbd buds for sale uk, hemp, buds for sale uk, cbd flower for sale uk, high cbd hemp buds,
    cbd buds uk for sale, cbd buds online buy uk, hemp flowers wholesale uk, cheapest cbd flowers ukMarijuana weeds, buy marijuana weed online,
    marijuana weed in UK, marijuana weed for sale, where to order marijuana weed, cheap marijuana weed online, best quality marijuana weed,
    how to buy marijuana weed, marijuana hash, buy marijuana hash online, marijuana hash for sale, where to buy marijuana hash, buy marijuana hash online UK,
    buy marijuana hash in Germany, buy marijuana hash in Belgium, top quality marijuana hash, mail order marijuana hash, cheap marijuana hash
    You can buy Weed, Cannabis, Vape Pens & Cartridges, THC Oil Cartridges, Marijuana Seeds Online in the UK, Germany, France, Italy, Switzerland,
    Netherlands, Poland, Greece, Austria, Ukraine. We deliver fast using next Day Delivery.
    THC vape oil for sale, dank vapes for sale, buy dank vapes online, mario cartridges for sale, weed vape, thc vape, cannabis vape, weed vape oil,
    buy vape pen online, buy afghan kush online, blue dream for sale, marijuana edibles,

    Visit here https://www.dankrevolutionstore.com/ to know more.

    ReplyDelete
  10. Big Truck Tow: Heavy Duty towing service san jose

    We're rated the most reliable heavy duty towing san jose service & roadside assistance in San Jose!
    Call us now! We're ready to help you NOW!

    Since 1999, tow truck san jose has provided quality services to clients by providing them
    with the professional care they deserve. We are a professional and affordable Commercial
    Towing Company. BIG TRUCK TOW provides a variety of services, look below for the list of
    services we offer. Get in touch today to learn more about our heavy duty towing


    Click here to Find tow truck near me

    ReplyDelete
  11. Keto Pills The Fastest Way to Get Into Ketosis?
    Keto diet pills reviews to let you know how to get into ketosis fast and feel
    young & energetic. These keto diet pills work wonders when taken as advised.
    Read This Informative article from top to bottom about Best Keto diet pills reviews & See
    Keto pills can help you to get into ketogenesis quickly and enjoy life-long benefits of
    maintaining healthy weight.our amazing Keto Diet Pills Recommendation at the end!
    How to get into ketogenesis ?
    If you Don’t know Where to buy keto diet pills click here.
    To Know More Information Click https://ketodietpillsinfo.com/ here.

    ReplyDelete
  12. crowdsourcehttp://www.incruiter.com recruitment agency.

    We ’incruiter’ provide a uniquerecruitment agencies platform to various committed professionals
    placement consultancyacross the globe to use their skills and expertise to join as a recruiter and
    interviewer to empower the industry with talented human resources.Searching for the right candidate is never easy.
    job consultancy We use crowdsource recruitment to find right talent pool at much faster pace.
    Our candidate search follows application of a rigorous methodology, and a comprehensive screening to find an individual
    whorecruitment consultants is not only skilled but is also the right culture fit for your organization.
    Our interviewers are best in the industry,staffing agencies being experts from various verticals to judge right
    candidate for the job. They interview candidates taking into account primarily defined job specification of our clients and targeting
    them for needs of the organization.Thinking about payment?placement agencies Don’t worry, you pay when you hire.
    Whether you are a startup or an established enterprise, join our 10x faster recruitment process that reduces your hiring process by 50% and give you
    manpower consultancyefficient results.

    check our website:http://www.incruiter.com.

    ReplyDelete
  13. ez battery reconditioning reviews - How to Recondition a battery .

    ez battery reconditioning reviews - You can now easily revive your old batteries with
    this ez battery reconditioning pdf which provides step by step instructions ... for How to recondition a battery

    For more information Visit https://ezbatteryreconditioninginfo.com/ here .


    ReplyDelete
  14. Talk with Strangerstalk to strangers in Online Free Chat rooms where during a safe environment.
    From friendships to relationships.omegle teen Talk With Stranger is that the best online chatting site.
    Its the simplest alternative to airg chat, Badoo , omegle & mocospace. If you're keen on speaking
    with people on the web ,chat random or want to seek out omegle girls, do free texting or sexting, make new friends.
    you'll find your omegle lady here. Please note this is often not a sexting site so you can't do sexting
    online. this is often a familychatous friendly chat site. we've voice chat if you would like to try to to phone
    chat online. Our most viral is that the 1-1 one on one random chat.talkwithstranger No check in on login needed.
    we've teengers also asanonymous chat older people that want to satisfy new people. Online random chat is that the best
    chatrandom alternative.

    ReplyDelete
  15. ترفند برد و آموزش بازی انفجار آنلاین و شرطی، نیترو بهترین و پرمخاطب ‌ترین سایت انفجار ایرانی، نحوه برد و واقعیت ربات ها و هک بازی انجار در
    اینجا بخوانید
    کازینو آنلاین نیترو
    بازی حکم آنلاین نیترو
    بازی حکم آنلاین
    Introducing the Nitro Blast game site
    معرفی سایت بازی انفجار نیترو
    همان طور که می دانید بازی های کازینو های امروزه از محبوبیت ویژه ای برخودارند که این محبوبیت را مدیون سایت های شرط می باشند. با گسترش اینترنت این بازی ها محدودیت های مکانی و زمانی را پشت سرگذاشته و به صورت آنلاین درآمده اند.
    بازی انفجار نیترو
    بازی انفجار
    یکی از محبوب ترین بازی های کازینو، بازی انفجار می باشد که ساخته سایت های شرط بندی می باشد و امروزه از طرفداران ویژه ای برخودار است. با گسترش اینترنت سایت های شرط بندی مختلفی ایجاد شده اند که این بازی را به صورت آنلاین ساپورت می کنند. یکی از این سایت ها، سایت معتبر نیترو می باشد. در این مقاله قصد داریم به معرفی
    سایت بازی انفجار نیترو بپردازیم.
    سایت پیش بینی فوتبال نیتر
    سایت پیش بینی فوتبال
    بازی رولت نیترو
    کازینو آنلاین

    Visit https://www.wmsociety.org/
    here for more information

    ReplyDelete
  16. Best place to design your Digital Business Crad + Mini website in Rs.99/- only
    Miniwebsite
    Digital Visiting Card
    Digital Marketing

    ReplyDelete
  17. Collection Original Amber Handmade Jewelry at amber jewelry shop.
    Only we made Jewelry in our factory by experienced craftsmen: ring, earrings, bracelet, brooch, Baltic amber

    ReplyDelete
  18. Ceramic Pro Coating in Miami, Paint Protection Coating, Leather Protection, Fabrics Guard Installation,
    Windshield Hydrophobic Coating, Auto Detailing

    ReplyDelete
  19. Good blog. Keep sharing. I love them Are you also searching for ajman assignment help? we are the best solution for you. We are best known for delivering writing services to students without having to break the bank

    ReplyDelete
  20. The Ftoc Stock Overview offers real time stock price updates. All you need to do is open the application and you can view Streaming stock prices of your favorite stocks.

    ReplyDelete

Blogroll

Popular Posts