Using ng-selected in Angular-UI select functionality

Code Snippet:

<div class="form-group col-md-4">
      <label for="lenderBusinessState">Select State</label>
      <div class="input-group select2-bootstrap-append">

        <ui-select name="lenderBusinessState" ng-model="lenderInfo.modelState.selected" theme="select2" class="form-control">
          <match placeholder="Select Lender State">{{$select.selected.stateName}}</match>
          <choices repeat="state in states | filter: $select.search">
            <span ng-bind-html="state.stateName | highlight: $select.search" ng-selected="selectState(state.stateId)"></span>
          </choices>
        </ui-select>

        <span class="input-group-btn">
          <button type="button" ng-click="lenderInfo.modelState.selected = undefined" class="btn btn-danger">
            <span class="glyphicon glyphicon-trash"></span>
          </button>
        </span>
      </div>
    </div>

JavaScript Function:

$scope.selectState = function(stateIdPassed)
{
    console.log(stateIdPassed);
    if(stateIdPassed == $scope.stateId){
        return 'selected';
    }
}

The user is facing prefilled ui-select input issue and seeking assistance. They are using ui-select. The issue arises when using ui-select tags compared to regular options tags. What suggestions do you have to solve this problem?

Answer №1

To preselect a value, simply assign it to lenderInfo.modelState.selected.

Feel free to use this code snippet when configuring the controller:

$scope.lenderInfo.modelState = {};
$scope.lenderInfo.modelState.selected =  {"stateId":1,"stateName":"Florida"};

Answer №2

Make sure that the desired pre-filled state is included in the states array. If the issue persists, feel free to create a plunker or fiddle for further investigation :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for utilizing bind-once or angular-once within HTML element properties

Is it possible to stop the creation of angular watchers for element attributes by using the bind-once or angular-once directive? I have implemented the Angular Once directive in my project. How can I implement it in the following scenario? <div conte ...

Seamless animation when collapsing element using angular and css exclusively

I am attempting to incorporate a collapsible feature into my application. Rather than relying on external libraries like jQuery, I want to exclusively utilize Angular. For demonstration purposes, I have created a very basic example here: http://jsfiddle.n ...

Make sure to give an item a little extra attention by highlighting or making it blink after it has

I have a collection of items that I utilize to construct an unordered list using ng-repeat. When a new item is added, I want it to stand out by blinking or having some kind of effect to grab the user's attention. While it would be easy with jQuery, I ...

Using the Parse JavaScript SDK within an Angular.js service: A step-by-step guide

Let me illustrate my issue with a brief example. Parse.initialize("nlxy5xYYZQ1fLfFkzcyLHOifkie1dOU0ZSxoxw1w", "IRBJO7nyd1vQquhMvnyMd298ZVJ0qWg1AjxBY5nr"); var People = Parse.Object.extend("People"); var app = angular.module('app', []); app.c ...

Tips for turning off hash-based redirection in AngularJS

Here is a specific URL: http://www.something.com/sometest/test/#registration Some code has been written based on #registration for Internet Explorer. However, when using AngularJS, it redirects to the following URL, which disrupts the logic: http://www ...

Experiencing an issue with Protractor e2e testing: "Encountered a Jasmine Spec timeout: WebDriver Control Flow Reset"

Seeking assistance with an ongoing challenge that has me stumped after days of searching I'm in the process of using Protractor for end-to-end testing of an AngularJS application While I have Protractor set up and running a test, whenever I try to r ...

Implementing an HTML5 Media Player with AngularJs via the $http Service

HTML View <audio ng-src="{{vm.videourlsce}}" autoplay preload="auto" controls="controls" autobuffer></audio> Retrieve data from a server in my controller using the $http service and update it to the player. var vm = this; vm.videourlsce = &a ...

Troubleshooting Tips: Investigating a Service Call in AngularJS 2 using ES6 Syntax

MY DILEMMA: I have recently started learning Angular2 and found myself wanting to debug a service call. The service appears to have been properly called, as evidenced by the view display. However, when trying to log the content of the variable holding t ...

Maximizing the potential of views and subviews in AngularJS

I'm a newcomer to AngularJS and facing some challenges with implementing multiple views. Can someone provide guidance on how to achieve this? My goal is to create a file explorer with two columns: the left column displays subfolders and files, while ...

Retrieve a specific progress bar by its unique identifier and use AngularJS to dynamically update its value

How can I update the value of a specific progress bar in AngularJS based on its id? I am looking for a solution to this issue. Below are the progress bars that I have: <progressbar value="0" id="seekbar1"></progressbar> <progressbar value= ...

Maintain the tab count in AngularJs navigation

As someone who is new to AngularJs, I am currently exploring the best approach for a tabController to remember the last clicked tab when transitioning to a new controller. Imagine having 3 tabs and clicking on tab 3; then navigating to a new controller and ...

AngularJS scope variable not getting initialized inside promise

I've encountered an issue with my code while using CartoDB. The goal is to execute a query using their JS library and retrieve some data. The problem arises when I attempt to assign the result as a scope variable in AngularJS, after successfully worki ...

User authentication in MEAN Stack using passport-local and $routeProvider for routing

When it comes to logging users into my application, I am utilizing passport-local. The login process involves a function called in my AngularJS controller: $http.post('/login', $scope.user).then(function (response){ if(response.data.success) ...

Access an element (such as a controller, service, or directive) located within a different module

Can functions from the same module or a different one be accessed? For example: var myFunction = angular.module("myModule").get("myFunction") … or: var myCtrl = angular.module("app").controllers["myCtrl"] When it comes to services, can an injec ...

Guide to dynamically generating Angular watchers within a loop

I'm looking to dynamically create angular watches on one or more model attributes. I attempted the following approach: var fields = ['foo', 'bar']; for (var i=0, n=fields.length; i<n; i++) { $scope.$watch('vm.model.&ap ...

A guide to populating a Dropdown List in Angular2 with data from a JSON response

I am facing an issue where the data I receive from my web server is showing up as undefined when trying to bind it into my front-end application. The array seems to be populated with the correct number of objects, and the data is binding to the component b ...

The issue arises when Angular routing fails to locate the Django template files

I have been working on a project that involves utilizing Django along with AngularJs routing. Within my URL configurations for Angular routing, I have the following code: app.config(function($routeProvider) { $routeProvider .when( ...

Angular routing template failing to execute inline JavaScript code

I'm facing an issue with my Angular.js routing implementation. I have successfully displayed the HTML code in templates using angular.js, but now I am encountering a problem with my template structure: <div id="map_canvas" style="width:95%; heigh ...

Activate the double-click function for C3 chart

I am working with a c3 chart and looking to display tooltips when clicking on a bar, and trigger something else on double click. The onclick event is available for the c3 chart: data: { columns: [], onclick: function(d, i) { ...

initiating an angular application

Currently, I am in the process of initializing an angular application using code that was previously developed by someone else: window.app = angular.module('angularYoApp', ['ui.router',]); window.bootstrap = function(){ angular.bo ...