Showing posts with label Bootstrap Latest News. Show all posts
Showing posts with label Bootstrap Latest News. Show all posts

How do you Get Bootstrap and Angular 2 to Work without Conflict?

Bootstrap and Angular 2

Bootstrap and Angular are perhaps the most vital coding tools for any coder. While the former turns you into a brute just grabbing and injecting data greatly reducing the time it would take to churn out a website, the latter is more systematic giving you more functionality and better viewing but comes with the sacrifice of more time and coding. Nevertheless, if you thought you can get better results on your CSS or JS project with your Bootstrap developer using either of the tools, you definitely haven’t tried using both of them. 

But, it is easier said than done. While the two platforms do present you with hoards of flexibility and functionality, it is quite easy to find yourself in a fix especially if you did not hire Bootstrap developers or if this is your first time. The two platforms work differently, with different requirements and, consequently, different results and viewing. But, that does not rule out the possibility of bringing the two tools together and bringing their best attributes to project.

What are the Differences and Similarities Between Bootstrap and Angular 2?


Bootstrap and Angular 2 similarities


Why Bootstrap and Angular 2 Don’t Get Along


The truth of the matter is, there is really no conflict between Bootstrap and Angular. However, there is a rule that suggests you should not use the full jQuery library on your Angular projects. The reason for this is because it makes it harder for you to realize the full potential of Angular. Additionally, if you would like to tweak the view on your project, it is best done based on the Angular data. Angular 2 comes with an add-on known as jqLite and this comes with the jQuery library. 

While the Angular and jQuery can be used differently to achieve the same goal, the same can’t be said of the Bootstrap JS, jQuery and Angular on the same pedestal. You can be able to work with Angular without jQuery. However, you do need the components of Bootstrap JS to get the front-end functioning. This is where the problem starts. 

Bootstrap JS library relies on jQuery and the way jQuery manipulates data is somewhat different from how Angular does it. Which is why, if you would like to use the two platforms together, you have to find a way to get rid of the reliance of Bootstrap on jQuery so you don’t have it impeding the functioning of Angular. That is why you get rid of it in the first place. 

jQuery is pretty basic with regards to how you build it into your DOM based on the events. It is simply a grab and injects kind of tool. So when used with a component from Bootstrap JavaScript like saying a button, what you simply have is like a toggle switch. Which when clicked goes to active if it is a button. If it is a checkbox, it is checked.

With Angular, the grabbing and injecting do not work. The data is processed and manipulated in a different way. Angular provides the Bootstrap components with variables. Then, based on the true/false nature of the component, Angular is able to bind a variable and then toggle it. Because the Bootstrap depends on jQuery to work and jQuery limits the output and benefits of Angular, you can’t have the two working on the same platform. Unless there is an alternative to locking jQuery out. 

How do you Get Bootstrap and Angular 2 to Work without Conflict? 


There are two ways that you can go around this. If you really have to use Bootstrap JS in its true form, you should load jQuery before Angular. That way, Angular will not use its built-in jQuery lite version. If it works, you save yourself lots of trouble. In case you get the “jQuery is not available” error, you have to make sure that $http.get() is working fine. 

If that doesn’t work and you’re not looking to hire Bootstrap developers, the other alternative is using UI Bootstrap. This is a lengthier and requires some coding knowledge but, it gets the job done. 

The UI Bootstrap is a project that is built by the Angular UI team that adds components that extend Angular. Unlike the Bootstrap JS, the UI Bootstrap has very different and very supportive requirements. These includes

  • Needs a Bootstrap CSS file
  • Needs Angular
  • Does not need jQuery


Now that you know what the UI Bootstrap is, how do you integrate it into your Angular 2 project the right way?

On an Angular App

Before you can bring the UI Bootstrap, you need to have created an Angular module and controller for the app. After that, you will need to create the variables for the Collapse and for buttons. Once these are in place, you can simply pick your UI Bootstrap file and add it to the project. With that, you can be able to include the ui.bootstrap function in your Angular module. 

In one simple step, you’re able to get the directives you need that work like the components of Bootstrap JS. 

For Button Directive

To apply the UI Bootstrap for the button directive, the correct way to use the checkbox button according to the UI Bootstrap Docs is adding the ng-model to what is being defined then you can proceed to add the btn-checkbox attribute. Everything should work if you get this right. 

For the collapse Directive

Things are a bit different here. You will need to open or close the panel on the basis of the true/false value on the iscollapsed variable. To toggle the panel, you will simply use ng-click = ! iscollaped” that will toggle the variable which consequently toggles the panel. 

In case you have problems along the way, here is a video that covers the ground on matters related to the UI Bootstrap and related matters. 

The truth is, Bootstrap and Angular 2 don’t have much of a conflict. The jQuery factor is the one that triggers the hibbie jibbies on either side of the spectrum. However, with these two tips, you should be able to get over the slight hiccups and get the two platforms to work together flawlessly. 

Bootstrap 4 - 10 Ultimate Features and Benefits

Bootstrap 4 Features


Download - Bootstrap 4.0.0-alpha 3 here


1. Sass Instead of LESS


Until now Bootstrap has used LESS as its main CSS prepocessor, but for the new major release, the style rules will be refactored to Sass, which is much more popular among frontend developers, has a huge contributor base, generally easier to use and offers more possibilities. Thanks to the powerful Libsass Sass Complier written in C/C++ Bootstrap 4 will compile much faster than before.


2. New Grid Tier for Smaller Screens


Bootstrap has a sophisticated responsive grid system that allows developers to target devices with different viewports. Bootstrap 3 currently has 4 grid classes for columns, .col-xs-XX for mobile phones, .col-sm-XX for tablets, .col-md-XX for desktops, and .col-lg-XX for larger desktops. Bootstrap 4 will enhance the grid system with a fifth one that will facilitate developers to target smaller devices under 480px viewport width.

The new grid class has taken the name of the previous smallest one, and pushed the current names of the grid tiers upwards by one notch. In Bootstrap 4 the large desktops will use the .col-xl-XX class selector. It’s important to know that despite the new name they didn’t add a new class for extra large screens but for extra small ones.

3. Introduces Relative CSS Units


Bootstrap 4 finally drops the support for Internet Explorer 8. That’s really a smart step as it allows them to get rid of pesky polyfills, and convert to relative CSS units. Instead of pixels, the new major release will use REMs and EMs that make it possible to implement responsive typography on Bootstrap sites. This will also increase readability, and make sites more accessible for disabled users.

If you want to try out how relative units work with the new Bootstrap 4, check out this demo on Codepen.


4. Brand New Bootstrap Cards


The development team decided to unify some previous elements of Bootstrap’s user interface, so they decided to introduce a new UI component called Cards. Cards will replace the former wells, thumbnails and panels, and will provide users with a more streamlined workflow. Don’t worry, cards will keep familiar elements, such as titles, headers and footers of wells, thumbnails and panels.

As cards will be more flexible than the current UI components, they will allow a bigger space for creative implementations. There are some pioneers out there who have already conducted experiments on Codepen with Bootstrap Cards. You can check them out, or create your own cards.


5. New Reboot Module


The new Reboot module replaces the previous normalize.css reset file. It doesn’t ditch it; on the contrary, it builds more rules upon it. The goal of the move was to include all generic CSS selectors and reset styles in a single, easy-to-use SCSS file. You can take a look at the source code here if you want to better understand how the new module works.

It’s good to know that the new reset styles smartly set the box-sizing CSS property to border-box on the <html> element, which is therefore inherited by each child element on the page. The new style rule makes responsive layouts more manageable. If you want to experience the difference between the content-box and border-box layout types, take a look at this handy demo provided by CSS-Tricks.com (it wasn’t created for Bootstrap 4, it just shows how box-sizing generally works).


6. Opt-in Flexbox Support


Bootstrap 4 makes it possible to take leverage of CSS3’s Flexbox Layout, however – as Internet Explorer 9 doesn’t support the flexbox module – the default version of Bootstrap 4 rather makes use of the float and display CSS properties to implement a fluid layout.

Flexbox has an easy-to-use layout that can be excellently utilized in responsive design, as it provides a flexible container that either expands or shrinks itself to fill the available space the best way. Only use the opt-in flexbox feature if you don’t need to provide support for IE9.


7. Streamlined Variable Customization


All Sass variables used in the new Bootstrap release are included in a single file called _variables.scss, that will significantly streamline the development process. You don’t have to do anything else apart from copying the settings from this file into another one called _custom.scss to change the default values.

You can customize many things such as colours, spacing, link styles, typography, tables, grid breakpoints and containers, column number and gutter width, and many others.


8. New Utility Classes for Spacing


Bootstrap 3 already has many practical utility classes such as the ones that change floating or the clearfix, but Bootstrap 4 adds even more. The new spacing classes allow developers to quickly change paddings and margins on their sites.

The syntax for the new classes is quite straightforward, for example adding the .m-a-0 class links a style rule that sets margins to 0 on all sides of the given element (margin-all-0). While margins use the m- prefix, paddings are styled with the p- prefix. In the development docs you can take a look at all the new spacing utility classes.


9. Tooltips and Popovers Powered By Tether


In Bootstrap 4 tooltips and popovers makes use of the super cool Tether library, a positioning engine that makes it possible to keep an absolutely positioned element right next to another element on the same page. This means tooltips and popovers will be automatically placed properly on Bootstrap 4 websites.

Don’t forget that as Tether is a third party JavaScript library, you need to separately include it in the HTML before your bootstrap.js file.


10. Refactored JavaScript Plugins


The development team refactored each JavaScript plugin for the new release using EcmaScript 6. With the smart utilization of the latest specifications and the newest enhancements, they intend to improve the frontend experience.

The new Bootstrap 4 has also undergone through other JavaScript improvements, such as option type checking, generic teardown methods, and UMD support, that will all work together to make the most popular frontend framework run more smoothly than ever before.

This article was taken from HONGKIAT. The whole purpose of sharing this article is to convey the news for my readers.