One View bind to different data models at different time (AngularJS)

109 Views Asked by At

I have created a view (A HTML file consisting of some divs and input boxes) and now I want to use that file as a view at different places but with different data models binded to it. "I mean change in ng-model of input tags"

One way is to make same view again and again and bind it with respective data model. But I don't want it.. How can I use only one HTML file as a view and bind it with different model at different place?

P.S : I am somewhat new to Angular-JS

1

There are 1 best solutions below

1
On BEST ANSWER

Do you mean useing different controllers with the same html template? If your using ngRoute you could set it up like this

$routeProvider.
  when('/route1', {
    templateUrl: 'myView.html',
    controller: 'myCtrl1'
  }),
  when('/route2', {
    templateUrl: 'myView.html',
    controller: 'myCtrl2'
  });

Here is a tutorial on setting up routing: https://docs.angularjs.org/tutorial/step_07