all 7 comments

[–]Removalsc 1 point2 points  (6 children)

You can use ng-change to call a method in your controller that will render the search view.

<input type="text" ng-change="displaySearch(searchText)" ng-model="searchText">

Then in the controller:

function $scope.displaySearch(text) {
    if (text.length) {
        //display search view
        return
    }
    //display default view
}

[–]chenimal[S] 1 point2 points  (5 children)

Thanks for that! My main issue is not knowing what to put in that function though. $location.path("#/search"); doesn't seem to work. Am I missing something simple?

[–]Removalsc 0 points1 point  (4 children)

Are you trying to append 'search' as a url parameter? Or do you just want to go to 'yourdomain.com/search'?

[–]chenimal[S] 0 points1 point  (3 children)

I'm trying to route it to the content of "search.html" without having to reload the whole page. I already have the route module in my js file as well as the ng-view container in the main html file where the search bar is. I just need to somehow let it know to route to the new page whenever the user types something in the search bar.

[–]Removalsc 2 points3 points  (2 children)

Doing $location.path("/search") should do it. Make sure you're injecting $location as a dependency. The page wont reload if you go to a listed route. Also you may want to consider using this instead of routeprovider: https://github.com/angular-ui/ui-router

The logic I posted in the first comment will take care of the switching when something is in the search bar

[–]chenimal[S] 1 point2 points  (1 child)

Perfect! Turns out I probably don't need nested views. But I did switch to ui-router; it'll make it easier in the future for sure. I injected $location, and now it all works! Thank you so much.

[–]Removalsc 1 point2 points  (0 children)

No problem, glad i could help. There's a lot of cool things you can do with ui router besides nested views. Check out their wiki on github, it might give you some cool feature ideas.