1

I am trying to access a mvc partial page in angular custom directive, code as shown below, but no luck. I took this solution from the link - ASP.NET MVC Partial View in an AngularJS directive but it doesn't seem to work for me.

(function (baseApp) {    
    var myDirective = function (DATA_URLS, $compile, $http) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                var ddd = $http.get(DATA_URLS.ROOT_PATH + "Views/Shared/specialView1").success(function (data) {
                    element.html(data);
                });
            }
        };
    };
    baseApp.directive('baseMyDirective', ["DATA_URLS", "$compile", "$http", myDirective ]);

}(angular.module('baseApp')));
9
  • what did you get if you type in browser address "DATA_URLS.ROOT_PATH + "Views/Shared/specialView1 with proper DATA_URLS.ROOT_PATH ? Commented Jul 17, 2014 at 13:19
  • Well, it says the resource can not be found. The DATA_URLS.ROOT_PATH just points to localhost/myapp... I just tried accessing other pages in the same folder as my partial view in the browser, but for all of them, it says, the resource cant be found Commented Jul 17, 2014 at 13:23
  • so specialView1 in angular view or MVC partial view ? Commented Jul 17, 2014 at 13:27
  • so path should be rather localhost:[port]/Views/Shared/specialView1 Commented Jul 17, 2014 at 13:35
  • Where can i find the port info and how do i use that in angular. Any idea. Commented Jul 17, 2014 at 13:53

1 Answer 1

0

Please use controller/action path in get call

(function (baseApp) {    
    var myDirective = function (DATA_URLS, $compile, $http) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                var ddd = $http.get(DATA_URLS.ROOT_PATH + "controller/action").success(function (data) {
                    element.html(data);
                });
            }
        };
    };
    baseApp.directive('baseMyDirective', ["DATA_URLS", "$compile", "$http", myDirective ]);

}(angular.module('baseApp')));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.