我嘗試更改angularjsng-click
函數中的$ scope變量。但angularjs似乎無法做到這一點。
下面是我的代碼在我的appController
:
// appController.js
$scope email = "[email protected]";
$scope.emailInfo = "[email protected]";
//emailOnClick() is a ng-click on DOM. It will be triggered when the user click a button, which is to save his email information
$scope.emailOnClick = function() {
$scope.email = $scope.emailInfo;
console.log($scope.email); //this will print "[email protected]".
};
console.log($scope.email); // this will print "[email protected]", but I
//want it to print "[email protected]" as I triggered the ng-click function to
//apply the change.
console.log($scope.emailInfo); //this will print "[email protected]".
我怎麼錯過?任何想法?
它不完全清楚你正試圖在這裏做。在你的代碼中**完全**是這個「全局變量」分配的,你爲什麼試圖做到這一點?全局變量永遠不是好事。 – Claies
您定義了一個點擊事件,但沒有運行它。 –
嘗試通過在控制器中以'$ scope.emailInfo'開始,使用不是''''的默認值,比如'test @ aol.com',並將其綁定到頁面的某處。一旦你點擊,看看它是否改變它。 – idotpdot