0

I have a angularjs controller named 'FilterController' in my application . It's the controller that the user use to filter some data. When the user click on Search, I call a Mvc method that return an object with the data. This work well, but the problem is to show the data that i retrive

How can I load this data in a new controller that show this data?

In the model i have this class

public class DPIModel
{
    public List<Dpi> listDpi{ get; set; }
}

Then the data are contained in a json that have this class The html is already loaded(because search is an ajax call) The html is like that

<div ng-controller="DPIController">
<div ng-repeat="item in listDpi">
    {{item.name}}
</div>

name is a property of dpi class

1
  • You can use factory and use it in another controller Commented Apr 8, 2015 at 10:26

1 Answer 1

1

Hope this helps :)

In the script:

(function () {
        var app = angular.module("ngHttpApp", []);
    }());


    (function () {
        var order = function ($http) {

            var getOrdershttp = function () {
                return $http.get('api/order')
                  .success(function (result) {
                      return result.data;
                  });
            }
            return {
                getOrdershttp: getOrdershttp
            };
        }
        var app = angular.module("ngHttpApp").factory("order", order);
    }());


    (function () {
        var app = angular.module("ngHttpApp").controller('HttpExampleController', function ($scope, order) {

            order.getOrdershttp().then(function (result) {
                $scope.httporders = result.data;
            });
        });
    }());

And in the HTML

    <div ng-controller="HttpExampleController">

        <h4>http over controller and factory</h4>
        <p ng-repeat="p in httporders">{{p.OrderId}}</p>

    </div>
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.