Steps to automatically populate a textbox with a default value using ng-model

Presented in HTML format:

<div class="row" ng-app="">
    <form>
         <input type="text" ng-model="link" name="link"
                class="form-control" id="yesklinkshjhs3" 
                value="hello" placeholder='Link for your post.'>
    </form>

    <small><a href='' ng-bind='link' class="thelink"></a></small>
</div>

This HTML code was created specifically to address an issue. Although it may contain errors, the main problem is that the textbox cannot be prefilled with a value when using ng-model.

If the ng-model is removed, the value appears. However, I require the form to be prepopulated to allow for easy editing of a post. How can I achieve this?

I attempted removing ng-model, which resolved the issue but I need it in place to display real-time changes in the next box. My experience with Angular is limited.

Here is the JSFiddle link: http://jsfiddle.net/iamrahulkumar001/wksapfr2/

The textbox remains empty despite attempts to prefill it.

Answer №1

It appears there are a few adjustments needed for your JSFiddle code. To begin, make sure to utilize the ng-app directive in order to bootstrap your application correctly. Additionally, don't forget to register MyCtrl as a controller. Lastly, consider assigning a default value to inputValue within the MyCtrl controller. Take a look at this revised example below which addresses these key points.

var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', MyCtrl);

function MyCtrl($scope) {
    $scope.inputValue = 'sjks';
    $scope.$watch('inputValue', function(thisValue) {
        $scope.inputValueEcho = thisValue;
    });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
    <input data-ng-model="inputValue" data-ng-trim="false" value='sjks'/>
    <p>This value: ----<span data-ng-bind="inputValue"></span>----</p>
    <p>This value (echo): ----<span data-ng-bind="inputValueEcho">dddddd</span>----</p>
</div>

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

Retrieving information from metaweather API and displaying it on an angularjs webpage

I am in the process of developing a basic weather application that can retrieve weather information for any city. The API I am using has two main stages: 1) Input the name of a city to get its "where on earth ID" (woeid). 2) Use the woeid to search for the ...

When implementing protractor spyOn() with jQuery's ajax() function, an error is triggered stating 'ajax() method is non-existent'

I am currently testing the functionality of using AJAX to submit a form. Below is the Protractor code for the test: describe('login.php', function() { it("should use ajax on submit", function() { browser.get('/login.php'); spyOn($ ...

Issue with AngularJS custom filter resulting in empty data output

Looking for help with applying a filter to data retrieved from Firebase. This is how my HTML appears: <span ng-bind-html="game.rating | ratings"></span> Note: Removing "| ratings" results in the original text being displayed from Firebase. ...

Exploring the method of accessing one Vue plugin from another plugin with the use of Vue.prototype

I'm currently working on developing a Vue plugin aimed at simplifying the management of authentication state throughout my application. This particular plugin will require interaction with other Vue plugins such as vuex, vue-router, and vue-apollo (fo ...

What is causing the sorting table to fail in React when using useState?

import React, { useState } from "react"; import "./App.css"; const App = () => { const [data, setData] = useState([ { rank: 1, name: "John", age: 29, job: "Web developer", }, { rank: 2, name: "Micha ...

Understanding the optimal timing for when the user interface is fully functional in React/Redux

I am seeking to determine the time it takes for my app to be fully "ready" for user interaction. The app loading process includes the following steps: DOM load. Initial React render. HTTP calls triggered from various componentDidMount()s HTTP calls retur ...

Navigating the techniques of filtering an object with an array

I am looking to filter this object using the aaData array in order to display only unique values. For example, if the first item has the name "testowy2" and the second and third have the name "testowy", I want to show only one instance of "testowy". var j ...

Discovering the Nearest Object on a Line in Three.js

In my project using Three.js, I am building a simulation of a robot that needs to detect obstacles. More specifically, the robot should be able to determine the distance to the closest obstacle directly in front of it. How can I achieve this using Three. ...

A password-protected website scraper using Node.js

When using nodejs to scrape a website, everything works fine on sites without authentication requirements. However, when attempting to scrape a site with a login form, only the HTML from the authentication page is retrieved. I am able to get the desired HT ...

Guide to filtering out cookies using express-winston

After reviewing the README for express-winston, it appears that removing the headers from the logged line is quite straightforward: we can easily do so by adjusting the requestWhitelist option. However, this will disable logging all headers. Is there a wa ...

Tips for avoiding API calls at specific intervals while in the process of logging out from a web application

I have integrated a 60 second timer observable in my Ionic/Angular app, which emits the current time synchronized with the server time. Every minute, I fetch permissions, settings, and other data by passing a token with each request. Upon logout, I revoke ...

Techniques for adding values to arrays in JavaScript

My Anticipated Result let Album = { album_desc: AlbumTitle, id: 1, album_title: 'ss', AlbumDescription: 'sdsd', ImageName: 'image.jpg', album_pics: below array }; I am looking to dynamically p ...

How come the CSS doesn't animate when I use JavaScript to switch the class?

I've implemented the Animate.css library by Daniel Eden, which I obtained from this source. Utilizing the animated (typeOfAnimation) class allows me to easily animate elements on my website. Below is a snippet of my HTML: <button onmouseover="mak ...

How to create custom popups in AngularJS using sweetalert 2 and custom HTML

Utilizing SweetAlert2 with AngularJS has been a seamless process, thanks to this convenient port designed for AngularJS 1.x: https://github.com/socialbase/angular-sweetalert-2. In an effort to enhance my swal experience, I attempted to integrate custom HT ...

What is the best way to use the Object3D.lookAt() function to align an ExtrudeGeometry face with an object?

I'm trying to create a 3D Polygon that can face another Object, but I'm struggling to figure out how to do it. I was thinking of using ExtrudeGeometry, but I'm not sure how to apply the Object3D.lookat() function to it. Any suggestions would ...

What is the best way to retrieve a value from a JSON object using AngularJS?

Using nodeJS, the server sends a JSON object to the controller: data = { "question": "theQuestion", "answer": "theAnswer" }; res.json(data); In the controller, I attempt to manipulate the variable as follows: data = QA.get(); $scope.q = data[que ...

Is it possible for URLSearchParams to retrieve parameters in a case-insensitive manner

Is it possible for URLSearchParams to search a parameter without being case-sensitive? For instance, if the query is ?someParam=paramValue, and I use URLSearchParams.get("someparam"), will it return paramValue? ...

Obtaining Asynchronous JavaScript responses with Selenium Webdriver

We recently integrated an asynchronous JavaScript call into our website. I am currently working on configuring Selenium Webdriver to pause and wait for a response from this particular call. The event listener code snippet is as follows: $(document).on("a ...

Is there a way to alter the format of a URL?

I'm utilizing the ytdl-core library to access a URL for audio content. The provided URL is: https://r2---sn-gwpa-w5py.googlevideo.com/videoplayback?expire=1612552132&ei=ZEMdYNnJDumPz7sPyrSLmAw&ip=49.36.246.217&id=o-AFQLS1cSUJ6_bXBjMOIiWk1N ...

Creating a GET request in Node.js using the request module

Currently, I am using NODE to utilize the request module for sending a GET request to a website that has already been authenticated. They have provided me with a sessionID which allows me to make REST calls and interact with the data. I am facing some dif ...