2016-05-23 69 views
0

我有HTML代碼編輯個人資料頁面如下:

<img ng-src="{$root.user.userProfilePic}" /> 

其中$rootScope.user.userProfilePic = "imageUrlHere" />

然而,當我在同一個頁面更新userProfilePic再次使用控制器,配置文件圖像仍然保持不變。這不會發生,如果我使用$scope。我怎樣才能解決它?

UpdateUserProfilePicApi.then(function (res) { 
    $rootScope.user.userProfilePic = res.imgUrl; 
}); 

回答

0

沒有必要使用$根。嘗試這樣的:

<img ng-src="{{user.userProfilePic}}" /> 

這給了你預期的結果,因爲user.userProfilePic進行評估,其價值所取代后角被加載。

<img ng-src="{$root.user.userProfilePic}" /> 

但與此,瀏覽器嘗試加載一個名爲$ root.user.userProfilePic的圖像,這將導致失敗的請求。您可以在瀏覽器的控制檯中查看。

1

你缺少{{雙括號}},試試這個:

<img ng-src="{{user.userProfilePic}}" /> 

ng-src docs

0

你不需要使用$根爲$ rootScope是來自各方面的意見進行訪問。 從您的代碼中刪除$ root。

<img ng-src="{{user.userProfilePic}}" />