如果想在某个属性发生变化的时候执行某些操作,那么scope.$watch是最佳选择
https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$watch
//如果是中文...
$rootScope.$watch('session', function() {
if ($rootScope.session) {
var re = /[u4e00-u9fa5]/;
if (re.test($rootScope.session.last_name + $rootScope.session.first_name)) {
//has Chinese in name then firstname+lastname
$rootScope.session.display_name = $rootScope.session.last_name + $rootScope.session.first_name;
} else {
$rootScope.session.display_name = $rootScope.session.last_name + ' ' + $rootScope.session.first_name;
}
}
});