Different ng-include's on the same page: how to send different variables to each?

前端 未结 15 1342
北海茫月
北海茫月 2020-12-04 12:17

I\'ve got a page in my AngularJS app in which I would like to include the same html partial, but with different variables. If I do this in my main html:

15条回答
  •  抹茶落季
    2020-12-04 13:10

    The same "onLoad" does not get called for all ng-includes. Most likely, var is set to A, and then to B. The thing is, it is being shared across both includes, because they are on the same scope. ´var´, as a model in angularJS, is scope-dependant.

    In order for your partials to have separate values, they must each have their own scopes. The easiest way to do this would bet to set up a controller or directive and assign it to the Dom element where the ng-include is, and set your value within that scope.

提交回复
热议问题