Utilizing the indexOf Method in AngularJS

Here is my array: emp=["111","56"]. This is the code I have:

<input type="text" placeholder="Enter" class="form-control" name="Emp" ng-model="myModel.Emp" ng-required="currentStep ==2"/>

 <input type="text" placeholder="Enter" class="form-control" name="EmpS" ng-model="myModel.EmpS" ng-required="currentStep == 2"/>

<span ng-if="(emp.indexOf('{{myModel.Emp}}') > -1 ) ? (myModel.EmpS=''):(myModel.EmpS=emp.indexOf('{{myModel.Emp}}'))" ></span>

I'm having trouble with this code as it always ends up in the false condition. Can someone please assist me?

Answer №1

Ensure that this method is used correctly for optimal results.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="">

<div ng-init='emp=["111","56"]'>


 <input type="text" placeholder="Enter" class="form-control" name="Emp" ng-model="Emp" ng-required="currentStep ==2"/>

 <input type="text" placeholder="Enter" class="form-control" name="EmpS" ng-model="EmpS" ng-required="currentStep == 2"/>
<span ng-if="(emp.indexOf(Emp) == -1 ) ? (EmpS=''):(EmpS=emp.indexOf(Emp))" ></span>


</div>

</body>
</html>

<div ng-init='emp=["111","56"]'>

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

Having trouble with Gulp hanging on the task named 'some_task_name' when using gulp.parallel or gulp.series?

Out of the blue, my gulp configuration suddenly stopped working. It gets stuck on 'Starting...' when I use tasks with gulp.parallel or gulp.series. Just yesterday, the same config was running smoothly. Why did this sudden change occur? Here is a ...

Converting JSON to an Array with the help of PHP's json_decode

Currently, I am trying to read a json file by using the following code: $jsonStr = file_get_contents("connection.json"); $jsonParsed = json_decode($jsonStr,true); I would like $jsonParsed to be an associative array structured as follows: $jsonParsed = { ...

How can you prevent the browser from prompting to save your email and password when filling out a sign-up form?

I'm currently developing a PHP sign up form, but whenever I click on the sign up button, the browser prompts me to save the email and password. Is there a way to prevent this from happening? ...

Looping through a list using Powershell's Foreach statement and square brackets

I've been attempting to iterate through a list enclosed in square brackets that is generated after executing a PowerShell script. For example: $json = .\chainsaw_windows.exe search C:\Windows\System32\winevt\Logs -e "test3.co ...

I am looking to have the first option in the dropdown menu appear as a placeholder text

In my form, I have two phone number fields - one for mobile phone and the other for home phone. I need to make only one of them mandatory. Can someone please advise me on how to accomplish this? ...

The issue with implementing simple getElementsByClassName JavaScript in the footer of a WordPress site persists

I am facing an issue with a 1-liner JavaScript code in the footer where getElementsByClassName function doesn't seem to work for tweaking style attributes. The text "Hello World" is displaying fine, so I suspect it might be a syntax error? Here' ...

What is the best approach for managing caching effectively?

My SPA application is built using Websocket, Polymer, ES6, and HTML5. It is hosted on a Jetty 9 backend bundled as a runnable JAR with all resources inside. I want to implement a feature where upon deploying a new version of the JAR, I can send a message ...

What causes the transformation of [{"value":"tag1"} into [object Object] when it is logged?

Currently on my node.js server, the code I'm using is as follows: var tags = [{"value":"tag1"},{"value":"tag2"}]; console.log("tags: " + tags); My expectation was to see this in the console: tags: [{"value":"tag1"},{"value":"tag2"}] However, what ...

Create a new storefront JavaScript plugin for Shopware 6 to replace the existing one

I am attempting to replace an existing JavaScript plugin in Shopware 6. However, the code within the plugin file does not seem to execute. Here is my main.js: import MyCookiePermissionPlugin from './plugin/my-cookie-permission/my-cookie-permission.pl ...

Securely package tailor-made services within an application

Recently, I have been researching how to create custom services for AngularJS. However, all the examples I found demonstrate defining the service directly on my app using myApp.factory(...). For reference, you can check out the official docs for an example ...

Display the initial x list items without utilizing ngFor in Angular 2

In the template, there are 9 <li> elements, each with a *ngIf condition present. It is possible that 5 or more of them may return true, but the requirement is to only display the first 4 or less if needed. Priority is given to the order of the < ...

Adjust the bootstrap switch component to be in the 'checked' state when the mode is set to Dark

I have stored a theme for my web application in the localStorage and I want to dynamically add the checked value to the Switch component if the mode is set to 'dark', or unchecked if the mode is 'light'. However, whenever I set the them ...

What is causing my switch statement to not align with any cases?

Whenever I implement a switch statement, none of the cases seem to match the 'prefix' value. However, when I switch to using an if-else statement instead, everything functions correctly. What could be causing this discrepancy? Thanks in advance ...

Getting specific information from a cell in a table within an AngularJS application

I need to extract the data "Crab" from this table: Sushi Roll FishType Taste Level Cali Roll Crab 2 Philly Tuna 4 Rainbow Variety 6 Tiger Eel 7 Here is the code snippet that currently re ...

Explaining the jQuery $.post method

After a thorough search, I finally discovered the importance of adding return false; at the end of my JQuery code for posting data. Without it, my code wasn't functioning as expected. As a beginner in JQuery, I would appreciate some insights into the ...

How can I create distinct component IDs effectively with the Catberry Framework?

When working with Catberry, it is essential that all components have unique IDs. How can you ensure that each ID remains distinctive even within a complex structure of nested components? ...

Error message: "An issue occurred with the Bootstrap Modal in

I've designed an AngularJS app like so: <!DOCTYPE html> <html ng-app="StudentProgram"> <head> <title>Manage Student Programs</title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2. ...

In what way can I incorporate additional functions or multiple functions within an Express route to modify database information?

Currently, I am working on a project that involves Express and MySQL. One of the challenges I am facing is retrieving data from a connection.query and then utilizing that data in other functions within the same route. My goal is to use the array created in ...

Using Silverstripe to Transform Twitter JSON Data into Dataobject for Template Iteration

I am currently utilizing the twitter API to fetch a timeline that I intend to display in my template. The code below demonstrates how I am retrieving the feed: public static function getTwitterFeed(){ $settings = array( 'oauth_access_toke ...

What is the process of removing a document with Next.JS and MongoDB by utilizing next-connect?

Currently in the process of constructing my first CRUD application using NextJS/Mongodb and I've decided to utilize next-connect for handling the methods. As a newcomer to this field, I have managed to successfully create posts and update user profile ...