As I work on my Angular single page application, I realized that my approach so far has been incorrect. I am now implementing routing to handle server calls instead of using $ajax
or $http
. Here is an example:
.when('/contact', {
templateUrl : '/contentMore',
controller : 'contentController'
});
My main concern lies with the templateUrl
.
Currently, my code looks like this:
$.ajax({
url: "http://example.com/contentMore",
type: "GET",
data: {request:"Section_I_Part_1_Complete",part:"1"},
success: function(data){
$scope.robot.ajax = true;
$scope.robot.sectionStayActiveI = false;
theData = data;
$scope.$apply();
$scope.html = theData;
$('#shyBox').mCustomScrollbar({
theme:"dark"
});
$scope.background.push("I");
}
});
All content is fetched from the same URL, http://example.com/contentMore
, based on the data sent in the ajax request. Without this data, if the templateUrl remains just /contentMore
, nothing will be retrieved. How do I pass this essential data?
Should I encode the URL or use another method? Also, when the templateUrl loads, can this be considered a form of ajax request?
Looking forward to your insights and suggestions!