0

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

2
  • 1
    It depends on what you mean by use that file as a view at different places but with different data models but in many cases a html file can be used as a template Commented Jun 6, 2014 at 14:01
  • "I mean change in ng-model of input tags " Commented Jun 6, 2014 at 14:08

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

With this can I operate on say array1 with myCtrl1 and array2 with Ctrl2? I think I can but to be sure...

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.