"Clicking the button will clear the values in the input fields

I have encountered a strange issue that I've never seen before. When I try to input the value of scope upon clicking on <a>, everything works fine. However, if I have entered values in other inputs and then click on <a> again, the values in the rest of the inputs get cleared. Can anyone offer advice on why this might be happening?

file.html

<input ng-disabled="product.disabled" type="text" ng-model="product.productData.oldPrice" name="oldPrice" class="form-control" ng-pattern="/^[0-9]*$/" required>
<input ng-disabled="product.disabled" type="text" ng-model="product.productData.newPrice" name="newPrice" class="form-control" ng-pattern="/^[0-9]*$/" required>
<input ng-disabled="product.disabled" type="text" name="level" class="form-control" ng-model="product.productData.level" required>
<div class="input-group-addon level-add">
  <a ng-click="product.easyLevel()" class="add-field add-field-easy">
    <i class="fa fa-battery-quarter"></i>
  </a>                           
</div>

controller.js

app.easyLevel = function(){     
    app.productData = {
        level: 'fa fa-3x fa-battery-quarter text-primary level-higher-easy'
    }
}

services

userFactory.createNewCourse = function(productData){
    return $http.post('/api/courses', productData)
}

Variables: app = this, product is controller as. Issue: After filling the first two inputs and clicking product.easyLevel() to enter

'fa fa-3x fa-battery-quarter text-primary level-higher-easy'
into the third input, the values in the above inputs are being erased.

Answer №1

To properly modify the level property within the productData object, make sure to initialize the productData object first.


app.productData = {};

app.easyLevel = function(){     
    app.productData.level = "fa fa-3x fa-battery-quarter text-primary level-higher-easy";
}

Instead of using var app = this;, it's recommended to define var vm = this;.

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

Ways to retrieve the date of the chosen <td> cell in a calendar

Looking for a way to extract dates from the <td> elements selected by mouse? Here is my code snippet that highlights the TD upon selection: $(function () { var isMouseDown = false, isHighlighted; $("#schichtplan td") .moused ...

Display a complete calendar with the date picker on a webpage

Currently experimenting with React to build a straightforward application. Admiring the appearance of full calendars from these date pickers (once clicked): Material-UI React-Toolbox Wondering if it's feasible to present the full calendar directly ...

Issues with the functionality of straightforward AngularJS routing

I cannot figure out why the add screen is not routing correctly. Can anyone help me troubleshoot? Here is my app.js var moviesApp = angular.module('moviesApp', ['ngRoute']); moviesApp.config(function($routeProvider) { $routeProvid ...

Having trouble starting the server? [Trying to launch a basic HTML application using npm install -g serve]

I am in the process of creating a PWA, but I haven't reached that stage yet. Currently, I have only created an index.html file and an empty app.js. To serve my project locally, I installed serve globally using npm install -g serve When I run the co ...

Getting rid of the empty spaces between the lines of cards in Bootstrap 4

I want to eliminate the vertical space between the cards in my layout. Essentially, I want the cards to maximize the available space. I am open to using a plugin if necessary, but I have not been able to find any relevant information online (maybe I used t ...

Double injection of Redux-saga

I've encountered a strange issue with my redux-saga - it's being called twice instead of just once. Here is the action that triggers the saga: export function createRequest (data) { return { type: CREATE_REQUEST, payload: {data} }; ...

Problem with the content-editable attribute

My goal is to make each div with the class .edit editable by adding the contenteditable property: $(document).ready(function() { $(".edit").attr("contenteditable", "true"); }); However, after applying this, I found that clicking on a div with content ...

Eliminate the array from the data retrieved through an http request in AngularJS

Currently, I am making an http call to retrieve data from a database. This process involves calling 6 different types individually. $scope.getAll = function() { var url = 'http://someurl/'; var allObjects = []; $sc ...

Setting nodeIntegration to false led to an Uncaught ReferenceError: require is not defined when trying to access Object.url (external "url":1) in the electron-react-typescript environment

After setting nodeIntegration to false, I encountered the following error message: "Uncaught ReferenceError: require is not defined at Object.url (external 'url': 1)". https://i.sstatic.net/galzh.png Upon clicking on the link referring to "exte ...

set available date with angular bootstrap datetimepicker

Currently, I am utilizing an angular bootstrap datetimepicker plugin that can be found at https://github.com/dalelotts/angular-bootstrap-datetimepicker. My goal is to configure the calendar so that only dates within the range of today and seven days in t ...

I have an Angular factory that I need to simulate in an actual browser environment, rather than just during testing

Instead of using mocha or jasmine, I am looking for a way to test my angular app and mock certain factories/services directly in the real browser. Right now, I manually swap out the ones that need mocking with others that have the same name during the buil ...

I can view the data retrieved in the console, but I am having difficulty displaying it on the screen

I have successfully retrieved data from the API, as indicated by the output in my console. However, I am facing issues in displaying this data on the webpage due to a potential error in my code structure. Despite this, I can confirm that the fetched data ...

Display modal after drop-down selection, triggered by API response

Currently, I am working on integrating an API to enable users to make payments through a modal. Users should be able to enter an amount and select a payment frequency. I have successfully extracted various payment frequencies from the API response and pop ...

What is the best way for me to determine the average number of likes on a post?

I have a Post model with various fields such as author, content, views, likedBy, tags, and comments. model Post { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt id String @id @default(cuid()) author U ...

The webpage freezes when attempting to run jQuery with Selenium

I'm currently facing an issue where my selenium script hangs the webpage whenever I try to find an element using jQuery. The script doesn't execute and a pop up appears in the browser with the message "A script on this page may be busy, or it may ...

Setting a default value in a multi-select dropdown using react-select

I have taken over management of my first React app, and I am facing a seemingly simple change that needs to be made. The modification involves an email signup page where users can select their interests from a multi-select dropdown menu. My task is to mak ...

The app.html for the skygear/react-chat-demo is malfunctioning

I followed the instructions provided in the Skygear manual at https://docs.skygear.io/guides/advanced/server/ The skygear-server-darwin-amd64 started successfully. Then, I attempted to run the react-chat-demo project from https://github.com/skygear-de ...

Stop inserting repeatedly if there is no new data available

I'm looking for a simple way to implement an if-else statement in my AJAX code to display new data only once it's found, without repeating the same data. Also, I need to figure out how to store the last ID as a variable so that I can use it when ...

Ag-Grid: Matching colors with filtering functionality

Can AG-Grid be configured to highlight matching cells during quick filtering? For example, if I have the following data: [ { firstName: 'Tom', lastName: 'Doe', company: 'Tesla' }, { firstName: 'Tim', lastName: & ...

Is it possible for setInterval to trigger restarts in Apache?

Although I am not a professional coder, I have been teaching myself by experimenting with code snippets. I enjoy playing around with coding experiments as a way to gain experience. I attempted to load PHP into a div, which worked fine. However, when I tri ...