Expression or ng-bind doesn't display

Let me explain the situation: (in controller)

var userData = $http(
{
    method: "post",
    url: "http://localhost/t-app/mobile-data/update-tasks.php",
    data: {
        done_tasks : $scope.done_tasks,
        job_id: $routeParams.job_id,
        employee_id: $scope.user_id,
        },
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});

userData.success(function (userdataobject)
{
    $scope.message = userdataobject["message"];
    $scope.status_id = userdataobject["status_id"];

    $location.path("/taskStatus");

});

Now, this is how my route is set up:

$routeProvider.when('/taskStatus', {templateUrl: 'partials/task-status.html'});

and in my task-status.html:

<div ng-if="status_id == '1'" style="color:black">
    <h4 class="text-center" >{{message}}</h4>
    <div ng-bind="message"> </div>
    You are the one
</div>

<div ng-if="status_id == '0'" style="color:black">
    <h4 class="text-center">{{message}}</h4>
    You are not the one 
    <div ng-bind="message"></div>
</div>

The issue I'm facing now is that the {{message}} expression and ng-bind="message" are not displaying correctly on the task-status.html page.

Answer №1

To ensure that prototypal inheritance is in effect, incorporate a '.' in your models instead of using .

If you find it necessary to utilize a primitive type, there are two alternatives:

  1. Utilize $parent.parentScopeProperty within the child scope to prevent the creation of its own property.
  2. Create a function on the parent scope and invoke it from the child, transferring the primitive value upwards (though this may not always be feasible).

It is advisable to use objects rather than primitive type variables in Angular. Follow this approach consistently.

In the controller, instantiate an object with those attributes and make use of it.

$rootScope.commonObject={message:'',status_id:''}
$rootScope.commonObject.message = userdataobject["message"];
$rootScope.commonObject.status_id = userdataobject["status_id"];

In the View,

<div ng-if="commonObject.status_id == '0'" style="color:black">
            <h4 class="text-center">{{commonObject.message}}</h4>
            tum nhi ho 
            <div ng-bind="commonObject.message"> </div>
        </div>

Reference: https://github.com/angular/angular.js/wiki/Understanding-Scopes

Answer №2

userInformation.success(function (userinfo)

userinfo holds various fields as outlined in the documentation:

  • data{string|Object} – The transformed response body.
  • status{number} – HTTP status code of the response.
  • headers{function([headerName])} – Get headers function.
  • config{Object} – The original configuration object used for the request.
  • statusText{string} – HTTP status text of the response.

The data field contains the response data, so you can access it like this:

$scope.message = userinfo.data["message"];
$scope.status_id = userinfo.data["status_id"];

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

Eliminate the listener if the connected function contains a binding

Here is a code snippet to consider: class Test { constructor() { this.breakpoints = {}; } add(options) { // Register the media query this.breakpoints[options.breakpoint] = window.matchMedia(options.breakpoint); ...

What is the best way to target a dynamically generated input field with JQuery or JavaScript?

This select input field is dynamic, meaning that the options will change based on the user's previous selections. <select name="vehicle"> <?php $loop = new WP_Query( array( 'post_type' => 'fleet') ); ?> < ...

The requested resource in Angular 5 does not have the 'Access-Control-Allow-Origin' header present

I am currently utilizing angular 5 and attempting to execute the following web service getMethod() { let headers = new Headers(); headers.append('Access-Control-Allow-Origin', '*'); headers.append('Access-Control-Allow-Methods&ap ...

When the user clicks, display one div and conceal the others

https://codepen.io/leiacarts/pen/PoqRxNZ I need assistance with two specific tasks related to my website layout. Firstly, I am struggling to ensure that images displayed in the red sections remain constrained and automatically resize within the content di ...

Embed one module within another module and utilize the controller from the embedded module

I am attempting to create a module and inject it into the main module. Then, I want to inject the controller into the injected module but am facing issues. In my index.html file: <html ng-app="MenuApp"> <head> </head> <body> <d ...

At what point does Angular's link function execute?

It appears that this script only runs once before the page is displayed. However, is there any scenario in which it runs after the page has been rendered? I decided to experiment with different scenarios using this plnkr: angular .module('app&apos ...

Iterate over a dictionary, display an alert for each item, and halt the loop when halfway through the

I am working with a Dict that has the following data: var seatsDict = {}; seatsDict[5] = 5; seatsDict[5] = 10; seatsDict[5] = 1; seatsDict[1] = 20; In my HTML, I have a select element structured like this: <select id="registerParticipants"> & ...

How can I fill an HTML table with data stored in a JavaScript array of arrays?

I am struggling to populate an HTML table with data formatted as an array of arrays. Despite my efforts in writing the code, the data is only showing up in a single row. I have tried mapping the data in a nested loop but I am unable to implement it correct ...

A guide to iterating over an array and displaying individual elements in Vue

In my application, there is a small form where users can add a date with multiple start and end times which are then stored in an array. This process can be repeated as many times as needed. Here is how the array structure looks: datesFinal: {meetingName: ...

Transform JSON data into a formatted HTML table

I've been attempting to convert my JSON data from a URL into an HTML Table, but the table ends up empty. The JSON file is stored at . Below is the code that I used: <html> <head> <script type="text/javascript" src="https://ajax.go ...

Combining Vue.js with Laravel Blade

I've encountered an issue while trying to implement a Basic Vue script within my Laravel blade template. The error message I am getting reads: app.js:32753 [Vue warn]: Property or method "message" is not defined on the instance but referenc ...

Encountered a problem when attempting to upload files to AWS S3 using React and React AWS S3

One issue I'm facing is receiving a strange response when trying to perform a put operation in my bucket. I am utilizing the react-aws-s3 package which only requires the bucket name, user keys, and region in its configuration. It's puzzling as t ...

Retrieve the JSON data from the server's response

{"identifier":"2231f87c-a62c-4c2c-8f5d-b76d11942301"} After alerting the response data, I discovered the code snippet shown above. Now, how can I retrieve the value of the identifier? The controller is set up to return like this: return Json( new { ...

Encountering an issue when trying to download a PDF from an Angular 6 frontend using a Spring Boot API - receiving an error related to

When I directly call the Spring Boot API in the browser, it successfully creates and downloads a PDF report. However, when I try to make the same GET request from Angular 6, I encounter the following error: Here is the code snippet for the Spring Boot (Ja ...

Is there a way to include the request body (req.body) in the msg object using express-winston?

My current challenge involves logging {{ req.body }} using the msg: object in express-winston. Even after whitelisting the body with expressWinston.requestWhitelist.push('body');, it still does not appear in the log. export const accessLogger = ...

What is the best way to pass JSON data into a JavaScript function?

As a beginner in javascript, I have been struggling to find a solution for my problem for a week. The code example I am working with is shown below (all within an HTML page in the head tag) //example function 1 function randomString(len, charSet) { ...

The result of Document.getElementById can show as "undefined" despite the presence of the element

Currently, I am tackling a project that involves extracting information from a website. I have opted to use the 'puppeteer' library in Node.Js for this task. However, I am encountering an issue where Document.getElementById is returning "undefine ...

The requested resource for deletion could not be found

I'm having trouble deleting a document in Mongodb and I keep getting the "cannot get delete" error delete route router.delete("/delete/:id",(req,res)=>{ filmModel.deleteOne({_id:req.params.id}) .then(()=>{ res.redirect( ...

What is the best way to manually decrease the speed of an object's rotation using javascript?

Can anyone assist me with slowing down the mouse-controlled rotation of a 3D object in javascript? The current rotation is too sensitive and difficult to control manually. Below is the code I am using: <html> <head> <script src="js/thr ...

Using React JS and an Express API server, submit an object by making a fetch request

I am facing issues with the post method in fetch as my server is receiving an empty object from the client. Despite checking on the client side, I am unable to send the desired value. Below is the code for my server: const express = require('express ...