I want to create a $watch in a directive to a specific part of a json object but it doesn't seem to accept the syntax (no errors appear, but it never goes inside the watch)
link: function (scope, element) {
scope.JsonObject={
profs:{
prof1:[{
name:example1a,
id:example1b
}],
prof2:[{
name:example2a,
id:example2b
}]
}
}
scope.teachers=scope.JsonObject['profs']
//until here all ok
for ( var teacher in scope.teachers){
//stuff to do
console.log("creating watch of " + teacher);
scope.$watch('teachers[teacher]', function() { //here seems to be the problem (it doesnt seem to accept JsonObject.teacher)
//stuff to do
}, true);
}
JsonObject.teacherisundefinedso you can useJsonObject.profsorteacher.profs