本文介绍了通过从内同一控制变量NG单击角JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得已分配NG-点击函数内部的变量值

I want to get the variable value which has been assigned inside ng-click function

mainApp.controller('setSearchController',function($scope) {

  $scope.getQuery = function(userq)  //ng-click function
  {
    $scope.userq=userq;
  };

  alert($scope.userq);  // showing Undefined even after the click is made
// Once clicked I want to use **userq** value to make one $https call
//  apart from services,How to use userq here outside getQuery scope
});

在使用前NG-点击,它的确定以不确定的价值,但我所试图做的是使用相同的控制器,另一种观点认为,这将在NG-点击后呈现发生

before using ng-click , its ok to get undefined value but what I am trying to do is to use the same controller for another view , which will be rendered after the ng-click happens

.when('/search', {
   templateUrl: "../static/views/seachResult.html",
 controller: "setSearchController"
})

所以我想要一些后 $ HTTPS 搜查searchResult.html视图数据呼叫

so I want to fetch some searched data in searchResult.html view after $https call

推荐答案

下面看看我的回答:
 Pass值之间的角度JS控制器和服务

有同样的问题,我已经使用$事件侦听器的解决您的问题,并发出$

It is the same question, I have solved your problem with event listeners using $on and $emit

这篇关于通过从内同一控制变量NG单击角JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 07:18