Fixed the $apply() error