I'm writing an on-page JS app with angular which will be integrated into different pages on our main website.
The app is integrated on our page with the following code:
<div class="app-video-list" ng-app="videoList">
<video-list id="video-list" data-level="5"></video-list>
</div>
data-level
is used to filter the list. So far everything works fine.
Now I want to be able to change the level
on the website (not inside the angular app!) without reloading the page.
$("#video-list").attr("data-level", "3");
This changes the DOM-Element as expected, but it's not recognized by angular. I tried attrs.$observe
in the directive, but that didn't helped:
# CoffeeScript
angular.module('videoList').directive 'videoList', ($document, templateBase) ->
restrict: 'E'
replace: true
templateUrl: templateBase + 'video_list.html'
link: (scope, element, attrs) ->
attrs.$observe 'level', (value) ->
console.log 'level changed to ' + value
As we don't know by now who may implement our app as-well, I'm looking for a nice line of javascript like the one above!
Is there any way, that angular recognize a change of data-level
, without calling a function like $apply()
or $digest()
with jQuery?