1

I have this in nodejs

res.render('pages/dist/reset', {token:req.params.token});

and i can read it in reset.mustache

<body  ng-app="eyeApp" ng-controller="ResetController">  
        <div id="wrapper">
            <div id="layout-static">
                <div class="static-content-wrapper">
                    <div class="static-content">                                                                                  

                        <div id="wrap" ui-view class="mainview-animation animated"></div>

                         <!--wrap -->     
                    </div>
                    <footer role="contentinfo" ng-show="!layoutLoading" ng-cloak>   
                        <div class="clearfix">

                            <button class="pull-right btn btn-default toUp btn-sm hidden-print" back-to-top style="padding: 1px 10px;"><i class="fa fa-angle-up"></i></button>
                        </div>   
                    </footer>
                </div>
            </div>
        </div>
     {{token}}

    </body>

Controller from this file is ResetController.

ResetController:

 angular
      .module('telcoserv.eye.reset', [
        'telcoserv.core.services'      
      ])
      .controller('ResetController', ['$scope', '$theme','$http','$state','$window','$stateParams', function($scope,$theme,$http,$state,$window,$stateParams) {
        'use strict';          

        $scope.submit = function(){             
            alert('123');                  
            alert($scope.token);
    }

      }]);

alert($scope.token) is undefined. when i say {{token}} in reset.mustache i can read value but $scope.token i can not read in resetController. Why??

3
  • angularjs doesn't know about other objects that were rendered. You should initialise it in the controller: $scope.token = ... Commented Apr 23, 2018 at 8:18
  • i don't want to initialize $scope.token. I want to pass parameter 'token' to resetController Commented Apr 23, 2018 at 8:21
  • 1
    how about receiving it with $http.get('/pages/dist/reset').then((res) => {$scope.token = res.data;}), or something similar? You can't not initialise it to access it in your controller. Commented Apr 23, 2018 at 8:26

2 Answers 2

2
$scope.submit = function(){             
    alert('123');                  
    alert($scope.token);

    $http({
        method:'',
        data: {json : data}
        url: ''
    }).then(function(response) {
        //Success response
    }, function(error) {
        //Failed response
    });
}

use $http to call your api. in method you can put GET, POST, PUT, DELETE, OPTIONS according to your api.

put your URL.

Put your request body in data as JSON only applicable for PUT, POST, DELETE.

Sign up to request clarification or add additional context in comments.

3 Comments

I don't mean this. Maybe I did not correctly ask the question. Thank you for your time.
what's your question then ?
I will create again a question.
0

If you don't want to initialize some ways to achieve this and get that as parameter 1. Create a constant service for getting token and inject it as a parameter in your controller . you can refer to this article how to create the constant service https://lostechies.com/gabrielschenker/2014/01/14/angularjspart-9-values-and-constants/

2.On the route definition of the app , make use of the resolve in the route of the page using this controller and use of the same parameter and inject it as a dependency in your controller.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.