logo
Tags down

shadow

Cannot access global variable from JQuery on() method in Angular


By : Sophy Seang
Date : October 17 2020, 08:10 PM
seems to work fine I am attempting to change the variable "currSideNavId" inside the jQuery on() method using Angular6. The current code below gives me TS error: , Here is the one way of doing.
code :
export class TimelineCreatorComponent implements OnInit {
    currSideNavId: number;
    let me = this;
    ngOnInit (){
       this.timeline.on('select', function (properties) {
         console.log('selected items: ' + properties.items);
         me.currSideNavId = properties.items;

       });
    }
}


Share : facebook icon twitter icon

Access global variable in angular


By : Neil Charniya
Date : March 29 2020, 07:55 AM
it should still fix some issue Because you're using a template to render a view, there are two different executions: (1) your server is rendering a page (using the user var) and then (2) the browser runs AngularJS. So you can't pass a variable from (1) into (2).
However, there is a directive called ngInit that will parse an expression during bootstrap. If you're using Jade templates in ExpressJS, you could do something like this:
code :
div(ng-init='user = "'+user+'"')
<div ng-init="user = 'whatever-server-sent'"></div>

How get access to global variable from Factory Angular JS?


By : Roger
Date : March 29 2020, 07:55 AM
hope this fix your issue Although the answer suggested by @JBNizet is absolutely correct but if you are bound to use the code in the way it is, then you can do two things. First is to simply pass the $scope from controller to service call (which is not a cleaner approach is not recommended):
code :
$scope.deleteUser = function (idUser) {
    friendsFactory.delete(idUser, $scope);
}
$scope.deleteUser = function (idUser) {
    $rootScope.callingControllerScope = $scope;
    friendsFactory.delete(idUser);
}
friend.deleteAjax = function (event, id, type){
     console.log($rootScope.callingControllerScope.counter);
     // your code
}
.controller('FriendsController', ['$scope','$http', 'FriendsFactory', function($scope, $http, friendsFactory) {
    $scope.deleteUser = function (idUser) {
        friendsFactory.delete(idUser, $scope);
    }
 }]);

Access typescript global variable outside of angular controller


By : Iqbal Aissa
Date : March 29 2020, 07:55 AM
To fix the issue you can do I've one global variable called rowTag as array of Tag[] entity in main.ts file. ,
Any idea on how to make that variable observable
code :
class Tags {
    rowTags = [] 
    colTags = []
}
constructor($scope, $rootScope, tags: Tags) {
    $scope.CloseMe = this.CloseMe;
    $scope.tags = tags; // Tags service containing `rowTag` and `colTag`
    $scope.UpdateMe = this.UpdateMe;
}

How to access global variable in Angular 2 Component


By : Leonardo Monteiro
Date : March 29 2020, 07:55 AM
Any of those help I want to access google api library from angular 2 module in typescript. How to do that. When i try to access (gapi) i get the undefined. is there any NPM module that work as typescript library in angular 2 to which i can use or i have to use the js file. , You have in your code :
code :
    var gapi: any;
    console.log(gapi); // undefined
declare var gapi:any;

Access global variable in Angular (`LC_API`)


By : Bjoern
Date : March 29 2020, 07:55 AM
should help you out You could inject window into your component and then access the variable on there as traditionally in JS that is where global variables reside. See also https://stackoverflow.com/a/40222547/1260204
You can shape the expected interface in the constructor for type safety.
code :
constructor(@Inject("windowObject") private window: {LC_API:any})
shadow
Privacy Policy - Terms - Contact Us © voile276.org