Git Product home page Git Product logo

Comments (6)

YousefED avatar YousefED commented on August 12, 2024

I'm using the following code myself:

$interval(function () {
                if (_this.scope.session_settings.auto_refresh) {
                    _this.scope.indexVM.refresh();
                }
            }, 1000 * 10);

Hope this helps!

On Mon, Nov 23, 2015 at 6:29 PM, Jordan Moore [email protected]
wrote:

I am not too familiar with Angular, but I am looking for a way to
periodically refresh the indexVM variable so the search results will
refresh every few seconds.

I have hooked a custom controller to the view with this code and I can see
in the console that the $scope.getData() function gets called every 5
seconds. I would like to somehow call the refresh method on the
IndexController here which I can see in the source is inside the
IndexDirective. I've tried using $scope.indexVM and injecting the
$controller service, but no success to get what I was looking for.
Controller

angular.module('demo.search', ['ngRoute', 'elasticui'])

.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/search', {
        templateUrl: 'search/search.html',
        controller: 'SearchCtrl'
    });
}])

.controller('SearchCtrl', ['$scope', '$timeout', function($scope, $timeout) {

    // Function to get the data
    $scope.getData = function(){
      console.log("Fetched data!");
    };

    // Function to replicate setInterval using $timeout service.
    $scope.intervalFunction = function(){
      $timeout(function() {
        $scope.getData();
        $scope.intervalFunction();
      }, 5000);
    };

    // Kick off the interval
    $scope.intervalFunction();
}])

HTML

I am using the SearchBoxDirective and the search results populate
appropriately when I type in the input field.

Search
Results
  • {{doc._source.doc.text}}


Reply to this email directly or view it on GitHub
#64.

from elasticui.

OneCricketeer avatar OneCricketeer commented on August 12, 2024

Looks promising, but where exactly do I place that?

I tried putting just that if statement inside my $scope.getData then placing that entire block directly into my SearchCtrl and both times I got ReferenceError: _this is not defined.

from elasticui.

YousefED avatar YousefED commented on August 12, 2024

I think you should just be able to call $scope.indexVM.refresh() im your
getData function. Does that work or is indexVM not defined?
On Nov 23, 2015 6:51 PM, "Jordan Moore" [email protected] wrote:

Looks promising, but where exactly do I place that?

I tried putting just that if statement inside my $scope.getData then
placing that entire block directly into my SearchCtrl and both times I
got ReferenceError: _this is not defined.


Reply to this email directly or view it on GitHub
#64 (comment).

from elasticui.

OneCricketeer avatar OneCricketeer commented on August 12, 2024

Correct, $scope.indexVM is undefined.

from elasticui.

YousefED avatar YousefED commented on August 12, 2024

Hi Jordan,

I think this has to do with the Angular Scope chain.

In my app for example, I set up the main controller as follows:

then, I do have access to indexVM on the MainController scope.

I hope this helps + you can find a good way to access the indexVM object on your scope

from elasticui.

OneCricketeer avatar OneCricketeer commented on August 12, 2024

Okay cool! That seems to work. For future reference, since your HTML seems to be hidden in GitHub, here it is again:

<body ng-app="stats" ng-controller="MainController" eui-index="'indexname'">

I do have an ng-view within my body tag, though, and my Controller is hooked to that (the ng-view is what I posted before). I ended up moving the eui-index directive from the view into the body tag of my index.html.

Thanks!

from elasticui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.