Reputation: 1089
I have a property inside an angular app called selected_tax, how can I pass a variable to this from jQuery?
I have a list of items that get filtered by their categories, I need a way to link to a pre-filtered list of category items. Currently, jQuery grabs a variable passed through the URL which is the category number.
Upvotes: 0
Views: 1098
Reputation: 5313
The method $location.search()
will get you access to the query string of the url as a JSON object. From the docs:
// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var searchObject = $location.search();
// => {foo: 'bar', baz: 'xoxo'}
you can add $location to a controller through the dependencies
var app = angular.module("app",[])
app.controller("myController",["$scope, $location",function($scope, $location) {
$scope.query = $location.search();
});
In your view template, you should then be able to use the query property to configure your jQuery calls.
Upvotes: 0
Reputation: 526
You can access the scope from the "outside world". Just make sure you wrap the code inside a setTimeout to allow angular to do its magic and then invoke digest.
<div ng-app="app" ng-controller="ctrl" id="myapp">{{xxx}}</div>
<script>
var app = angular.module("app",[])
app.controller("ctrl",["$scope","$log",function($scope,$log){
$scope.xxx = 'hello';
}])
</script>
<script>
setTimeout(function(){
$("#myapp").scope().xxx='gotcha!!! HAHA!';
$("#myapp").scope().$digest();
},0)
</script>
Upvotes: 1
Reputation: 12452
window.property = $('#input_3').val();
$scope.input3val = window.property;
Upvotes: 0