Is it possible to retrieve an input $scope from outside ion-view?


#1

Hi,

I have been trying to retrieve the scope of my search input but with no success. I think it’s because my search input is outside the ion-view but I am not sure. Any idea what am I doing wrong?

Here is my HTML:

<ion-side-menus>
  <ion-pane ion-side-menu-content>
    <ion-nav-bar class="bar-positive item-input-inset nav-title-slide-ios7">
      <ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-left header-nav-icon"></i> &nbsp; </ion-nav-back-button>
      <button menu-toggle="left" class="button button-icon ion-navicon"></button>
      <label class="item-input-wrapper">
      <i class="icon ion-ios7-search placeholder-icon"></i>
      <input type="text" placeholder="Search" ng-model="search.query">
      </label>
    </ion-nav-bar>
    <ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
  </ion-pane>

  <ion-side-menu side="left">
    <header class="bar bar-header bar-dark">
      <h1 class="title">Menu</h1>
    </header>
  </ion-side-menu>
</ion-side-menus>

<ion-view title="">
<ion-nav-buttons side="right">
  <button class="button button-icon ion-search" ng-click="doSearch(search.query);"></button>
</ion-nav-buttons>

<ion-nav-buttons side="right">
  <button class="button button-icon ion-refresh" ng-click="reloadPage()" ></button>
</ion-nav-buttons>

  <ion-content class="has-header image_background_section">...</ion-content>
</ion-view>

And my controller:

.controller('SearchController', [
	'$scope', 'SearchService', '$ionicLoading', '$location', 'appConfig', '$ionicPopup',
	function ($scope, SearchService, $ionicLoading, $location, appConfig, $ionicPopup) {

		$scope.doSearch = function() {
      console.log("Query...." + $scope.search.query);
		};
	}
]);

I have been struggling on this problem for a few days. Any help is very appreciate.

Cordially,

Hervé


#2

do you have a pen setup for someone to review?


#3

no sorry I dont have a pen. Does it work with ionic?


#4

a codePen… see example here http://codepen.io/ionic/pen/JsHjf with your sample code in it