How to build the function in AngularJS to chceck the last part of the url?
My examples:
#/menu1/123/edit
#/menu2/444/create/new
#/menu3/sumbenu1/333/create/new
#/menu4/submenu2/subsubmenu1/subsubsubmenu1/543/edit
The thing is:
123
444
333
543
are the ID's which are generated outside Angular
I need to check the last parts of my url: /edit
or /create/new
.
The length of the url will be different (number of /
inside url).
I have a controller in Angular to get the url:
.controller('urlCtrl', ['$scope', '$rootScope', '$location', function ($scope, $rootScope, $location) {
$rootScope.location = $location;
$scope.hashPath = "#" + $rootScope.location.path().toString();
}]);
I'm adding the #
character to the url because later I'm comparing it with my JSON.
I tried this solution but it didn't work (I also checked another solutions from this topic and nothing happened).
Any ideas?
EDIT:
Or how to check just the edit
or create
inside the url?
My solution is:
var path = $location.path();
var multisearch = path.search(/create|edit|new/);
console.log("multisearch: " + multisearch);