I'm using the angular UI router and breaking my pages up into partial views and then loading those. I'm noticing I can't seem to use jquery on the partial views. I have a main index page and then I'm inserting the partials using angular js.
Any sort of jquery I want to run on the code in any of the partials won't work.
Here's an example of the index page where I'm inserting the partials:
<div id="page-content-wrapper">
<div ui-view>
</div>
</div>
and then my ui router:
$urlRouterProvider.otherwise('/home');
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'global/partials/home.html'
})
.state('search', {
url: '/search',
templateUrl: 'search/partials/search.html'
})
.state('intake', {
url: '/intake',
templateUrl: 'intake/partials/intake.html'
})
});
and an example of one of the partials (a form) where I'm trying to run some jquery to find out the value of a form field:
<h1>Intake Form</h1>
<form name="intakeform">
<div class="form-group">
<label for="sourceSystem">Source System</label>
<select class="form-control" id="sourceSystem" ng-model="sourceSystem">
<option value="" selected disabled>Select Source System</option>
<option value="Cosmos DIV">COSMOS</option>
<option value="UNET">UNET</option>
</select>
</dv>
</form>
I have to auto populate the next three fields based on the value of this initial field and for some reason if the most basic jQuery isn't working:
function autoFill() {
$('select').on('change', function() {
alert( this.value );
});
}
Any ideas on how to get jQuery working on these partial views? Or should I just skip the ui router and just create these pages individually?
Full disclosure, we're using JAVA with JSP's and Adobe's CQ5 CMS if it helps. I would gladly do this with .Net, but the project is all JAVA (which I'm not very familiar with). This is why I tried to use Angular's MVC design pattern.
Also, I'm not getting any errors in the browser console and have all the necessary scripts included in the bottom of the page.
Any help is greatly appreciated.
P
You should get familiar with Angular directives that can do the job you're looking for.
Basically, here, you can use
ngChange
onselect
elements.In the partial :
In the controller :
EDIT:
On AngularJS, you have some useful directives to populate a
select
element and bind them to your model.Example :
It will populate your select element for each value stored in
$scope.items
. And then, the value will be updated in your model, as you putted the ngModel directive ($scope.sourceSystem
).