My Scenario:
My MVC controller is returning JSON data which is array of string
I tried all the possible solutions like twitter bootstrap typeahed for angular but nothing worked.
I read documentation but it also dint work for me.
Can anybody explain how to implement autocomplete step by step?
I have implemented it using jQuery but I dont want to use jQuery as Angular doesnt know the DOM updates by jQuery.
2
Answers
Finally I used Angular Material for the autocomplete and it works like a charm. Here are the steps to create autocomplete in Angularjs and MVC4
Step 1: Angular material has a dependency on
angular-animate.js
angular-aria.js
angular-messages.js
register these js files in your bundle config:
Register two css files as well: bundles.Add(new StyleBundle("~/Content/angularmaterialcss").Include("~/Content/angular-material.css")); bundles.Add(new StyleBundle("~/Content/angularmateriallayoutcss").Include("~/Content/angular-material-layout.css"));
Now include these files in shared or your page:
Now in your cshtml page add html code:
write below code into your app.js file:
Angularjs Material Autocomplete demo's-Angular Material Autocomplete
Once you have a demo running autocomplete file then modify it according to your need.
For bootstrap type ahead another link-bootstrap typeahed
Finally I was able to develop angular autocomplete text box using bootstrap typeahead.
To develop angular bootstrap typeahead with your service returning JSON data below are the steps:
You need to register:
jquery.js
bootstrap.js
angular.js
And to use bootstrap you need to add angular bootstrap dependency javascript file:
ui-bootstrap-tpls-0.14.3.js
In your bundle config register below files:
In your cshtml file add below code:
Render scripts and css in your shared or respective .cshml file:
Write below code in your respective cshtml file:
Now write below code in your app.js file:
My JSON data contains:
data.SYMBOL
data.NAME_OF_COMPANY
I want to display data.NAME_OF_COMPANY, so if you check in chtml code, I have written:
uib-typeahead=”stock.NAME_OF_COMPANY for stock in stocks.
In this way you can create a typeahead using angularjs and bootstrap.
Hope this helps someone who is stumbled upon this like me.