0

I used route resolve to prevent loading view before executing some functions, then I read here Error: Unknown provider: employeesProvider <- employees that I have to remove ng-controller, then I did

<div > <!-- ng-controller="navBar" has removed from here -->
    <div ng-include="'...../partitials/navBar.html'"></div>
</div>

here is the route provider

$routeProvider
.when("/ERPdocumentation/", {
            templateUrl : function(params){
                // code here
                return template
             },
            controller: "navBar",
            resolve: {
                filteredModules: function (searchForService) {
                   return searchForService.getfilteredModules();
                }
            }
        });

But, that made some functions no longer worked in navBar controller, for example, when I click this button:

<md-button ng-click="routeToSearchPage (searchString)">

, the functions doesn't works in the navBar controller:

angular.module("myApp")
 .controller("navBar", function ($scope,filteredModules, $location) {
    $scope.filteredModules = filteredModules;
    $scope.routeToSearchPage = function(searchString){
        console.log("route") // nothing happened here
        $location.search("search", searchString);
        $location.path($location.$$path);
    };
})
.factory("searchForService", function(){
 return {
        getfilteredModules: function(){
// code here to get search results 
        }
   }
 })

https://jsfiddle.net/e1vfrcrf/14/ Do i misunderstand something with those concepts?What caused this problem? and how to solve it?

Community
  • 1
  • 1
Hala Ba
  • 249
  • 3
  • 21

1 Answers1

0

Well, the solution I tried was not to use the route resolve at all, I's just return the search results from the service directly, this way:

        $scope.filteredModules = searchForService.getfilteredModules();
Hala Ba
  • 249
  • 3
  • 21