The $scope in Angular doesn't seem to be working as expected in the callback function, despite using $scope

I'm currently working on converting the JSFiddle found here to AngularJS: http://jsfiddle.net/danlec/nNesx/

Here is my attempt in JSFiddle: http://jsfiddle.net/leighboone/U3pVM/11279/

var onAuthorize = function () {
    updateLoggedIn();
    $scope.testname = "this works";
    Trello.members.get("me", function (member, $scope) {

        var test = member.fullName;
        console.log(test)
        $scope.$apply(function(){$scope.applytest = member.fullName;})
        $scope.member = member.fullName;

    });
};

Despite trying various solutions, I am facing difficulties assigning member.fullName to $scope.member. Even after using $scope.$apply(function(){}), an error keeps popping up:

undefined is not a function

It's frustrating as I'm running out of ideas on how to resolve this issue. :(

Answer №1

Check out the correct angular code snippet below To view the working fiddle, click here

HTML Connect To Trello

    </div>

    <div id="loggedin" ng-show="isLoggedIn">

        <div id="header">Logged in to as <span id="fullName">{{fullName}}</span>  <a ng-click="logout()" id="disconnect" href="#">Log Out</a>

        </div>
        <div id="output">
            <div ng-show="loadingCards">Loading Cards...</div>
            <div ng-repeat="card in cards">{{card}}<a href="{{card.url}}" target="trello" class="card">{{card.name}}</a>

            </div>
        </div>
    </div>
</div>

Javascript

function calendarCntrl($scope) {

$scope.cards = [];
$scope.fullName = '';
$scope.loadingCards = false;

$scope.logout = function () {
    Trello.deauthorize();
};
$scope.login = function () {
    alert('logging in');
    Trello.authorize({
        type: "popup",
        success: onAuthorize
    });
};

$scope.$watch(function () {
    return Trello.authorized();
}, function (val) {
    $scope.isLoggedIn = val;
});

function onAuthorize() {

    Trello.members.get("me", function (member) {
        $scope.fullName = member.fullName;

        $scope.loadingCards = true;
        // Output a list of all of the cards that the member 
        // is assigned to
        Trello.get("members/me/cards", function (cards) {

            $scope.cards.length = 0;
            angular.extend($scope.cards, cards);
            $scope.loadingCards = false;
        });
    });

};

Trello.authorize({
    interactive: false,
    success: onAuthorize
});

}

CSS

body {
font-family: arial;
font-size: 12px;
}
#loggedout {
    text-align: center;
    font-size: 20px;
    padding-top: 30px;
}

#header {
    padding: 4px;
    border-bottom: 1px solid #000;
    background: #eee;
}
#output {
    padding: 4px;
}
.card {
    display: block;
    padding: 2px;
}

Answer №2

After some consideration, I have come to the conclusion that setting it to the rootScope is the solution.

$rootScope.$apply(function(){$rootScope.applytest = member.fullName;})

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

Managing field placement as the table height grows: tips and tricks

I am encountering an issue with my dynamic form. When I click on the add button, a new row is added to the table. However, once there are more than 6 rows added, the table height starts covering the fields. How can I go about setting this so that the field ...

Controller variable in Angular not being updated in view

I am facing an issue with my Angular view not updating after changing a value in the controller through a partial. Interestingly, when I use console.log to log the changed values, everything seems to work fine. TestController $scope.testitem = 0; $sco ...

Removing value types in select with ngOptions

When using angularjs version 1.5, the ng-option is creating values with type annotations like this <select name="type" ng-model="type" ng-options="k as v for (k, v) in Providers"> <option label="Provider 1" value="string:prov1">Provider1&l ...

Navigating through the directories in PUG using the absolute path

Referring to the docs for PUG (), it states: If a path is absolute (example: include /root.pug), it gets resolved by prepending options.basedir. Otherwise, paths are resolved in relation to the file being compiled. To clarify, I understand that this in ...

Next.js presents a challenge with double-language applications

I am currently in the process of developing a web application using Next.js that will cater to users who speak my native language and English. I have a specific approach in mind: First, I plan to create a folder: /pages/en-us pages/ |--(all app pages) |- ...

Transmitting information in segments using Node.js

Recently delving into the realm of nodejs, I find myself tackling a backend project for an Angular 4 application. The main challenge lies in the backend's sluggishness in generating the complete data for responses. My goal is to send out data graduall ...

Adjust the content of an iframe based on the size of the screen

Hi there, I'm currently facing an issue with an ad that can't be resized. The support team suggested using two different ads - one for mobile and one for desktop. The dimensions of the ads are 720 x 90 and 300 x 100. I would like the ad to automa ...

Show the meta-field mp3 and place it in a lightbox container on the portfolio page

My Current Portfolio Gallery Setup: Currently, my portfolio gallery is displayed in a masonry grid format using the JIG plugin. This grid showcases images from my custom post_type. When clicking on a thumbnail, a lightbox pops up showing the full photo. T ...

Unexpected behavior: Promise.catch() fails to catch exception in AngularJS unit test

During the process of writing Jasmine unit tests for my Typescript app and running them via Resharper, I encountered an issue with executing an action when the handler throws an exception: describe("Q Service Test", () => { var q: ng.IQService; ...

Tips for showcasing an image on an HTML page

I am encountering an issue with my HTML page that includes a Button. When clicked, it is supposed to display an image using an Ajax call. The functionality works properly in Postman Rest Client. However, when accessed through a browser, it only shows raw ...

JQuery is failing to properly return the string containing special characters like apostrophes

Storing the name "Uncle Bob's Organic" in the data-Iname attribute caused a retrieval issue, as it only retrieved up to "Uncle Bob". Here is the process used for retrieving the value from the data-Iname: var itemName = $(this).attr("data-Iname"); T ...

What causes the timer to pause, and what steps can be taken to avoid it? (Using Javascript with Iframe)

On my website, I have a page where clients must view an advertisement for 20 seconds. The website is displayed in an iframe with a countdown timer above it. I've set it up so that the timer stops when the window loses focus to ensure the client is ac ...

Changing the value of a specific array element after removing it from a filtered ng-repeat resultList

I have a list of users where you can select a user by clicking on it, which then places the selected element into an object called $scope.selectedMember. The ng-repeat directive is being used along with a filter in a search box. It's crucial that $sco ...

Best practices for working with HTML elements using JavaScript

What is the best approach for manipulating HTML controls? One way is to create HTML elements dynamically: var select = document.getElementById("MyList"); var options = ["1", "2", "3", "4", "5"]; for (var i = 0; i < options.length; i++) { var opt = ...

What is the method of displaying a querystring on my Angular view page without relying on a controller?

My experience lies in utilizing AngularJS 1. This excerpt showcases the stateprovider configuration present in my config.js file: JavaScript .state('projects', { abstract: true, url: "/projects", templateUrl: "views/common/master_pa ...

Experiencing problems with CSS compatibility while transitioning from vanilla JavaScript to React

Currently, I am working on revamping the frontend of an app that was initially built with vanilla javascript and transitioning it to a React framework. However, I'm encountering some challenges with styling the HTML elements. Specifically, the textare ...

Oops! You can only have one parent element in JSX expressions

I'm working on creating a password input box, but I keep encountering an error when integrating it into my JS code. Here's the snippet of my code that includes TailwindCSS: function HomePage() { return ( <div> <p className=&q ...

What is the best way to transfer a value to the database using a distinct module?

I have recently set up a basic express project and added a file named lib/userhandler.js in the main directory. //lib/userhandler.js exports.addUser = function(req, res){ // Accessing our internal database variable var db = req.db; // Retrieving ...

Incorporating CSS Styles in EJS

Struggling with connecting my CSS files while using EJS. I've checked out another solution but still can't seem to get it right. Here is the code I used as a reference for my CSS file. EJS <html> <head> <meta charset="utf-8 ...

Change the size of the font with a slider in VueJS

I have been utilizing the project found at This particular project allows end-users to reuse Vue components as editable sections by providing a styler overlay for adjusting content within a div or section. After installation, I added a slider which now ap ...