New to Angular and experimenting with it to replace some jQuery functionality.
I have a basic UL/LI setup with countries and provinces:
<div ng-app="FindRep">
<ul class="country-list" ng-controller="LocController">
<li data-ng-repeat="country in countries">
<a data-repId="{{country.repId || '-1'}}">{{country.Name}}</a>
<ul class="provinces-list" style="display: none">
<li data-ng-repeat="province in country.provinces">
<a data-repId="{{province.repId}}">{{province.Name}}</a>
</li>
</ul>
</li>
</ul>
<!-- Testing here -->
RepID: {{RepID}}
</div>
The way I built this with jQuery, before experimenting with Angular, is if a country had a rep that existed for that entire country, as in didn't equal "-1", I would move to the next step, grab the RepID from a HTML5 data attribute:
var repId = $(this).data("repid");
And then proceed with other operations irrelevant to the question based on that ID.
If a rep did NOT exist for that country, that means there are individual reps for the provinces of that country, and I would use jQuery to show the list of provinces, allowing the user to click on one of them, and then proceed with other operations based on that repID.
This is probably very simple, but I keep reaching to jQuery, which I think is a common problem.
I'm pulling my initial data in via Web API. What I'd like to understand/figure out how to do is:
So if I have:
<div ng-app="FindRep">
Anywhere within my app, I'd like to be able to use {{repId}} {{repName}} and so on.
</div>
What I've Tried
I tried to use a factory to hold initial blank data about a rep, such as:
app.factory("rep", function() {
var data = {
repid: null,
repname: ''
};
return {
GetRepId: function() {
return data.RepID
},
etc.
}
And then using ng-click to call this function and access data from (this).
I'm rambling on, and I think I just need an example, or a push in the right direction. It's harder than I thought grasping this concept without using jQuery as a crutch.