4
\$\begingroup\$

I am using MVC+Angular. In MVC, I created partial views for search, listing, etc. I show them using:

@Html.Partial("_Search")
@Html.Partial("_Featured")
@Html.Partial("_Listing")

Previously each partial view had an ng-app and ng-controller.

Now I combined them all into one ng-app. I added ng-app to master page, and I just used the ng-controller in every partial view.

 <div ng-controller="Search" class="slide">
some ng-repeat goes here
</div>

Angular code:

angular.module("ProductListing", [])
.controller("Search", function ($scope,$templateCache, $http) {
 $(document).on("keyup", ".txtTempleSearch", function () {
 var searchTerm=$(this).val();
 $.get(configUrl + "SearchGrouped/" + searchTerm, function (data) {
 $scope.Results = JSON.parse(data)[0].result;
 $scope.$apply();
 });
 });
})
.controller('featured', function ($scope) {
 $.get(configUrl + 'Featured', function (data) {
 $scope.featuredTemples = data;
 $scope.$apply();
 });
})

Is this approach correct or is it better in terms of maintainability/performance/best practice to have a different ng-app for different partial views and use angular.bootstrap?

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Sep 1, 2015 at 6:18
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

I think this is primarily opinion based, but in the AngularJS docs, there is the following:

Use this directive to auto-bootstrap an AngularJS application. The ngApp directive designates the root element of the application and is typically placed near the root element of the page - e.g. on the <body> or <html> tags.

Also, note that is not possible to have nested ng-app, so, merging the group related controllers into one unique module is a good thing.

Quill
12k5 gold badges41 silver badges93 bronze badges
answered Sep 1, 2015 at 7:41
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.