我正在寻找从控制器更新范围值的'ng-href'网址。最初在页面加载网址被插入正常。但是之后 当我更改URL应该更新的范围时
<a ng-href=={{selectedValue}} /a>
//in my controller
$scope.selectedValue = "www.google.com"
//need to update this url in this function
otherButtonFn = function(){
//want to Update the url here
$scope.selectedValue = "www.yahoo.com"
}
//ng-href is loading initial url but not updating when $scope is called
<a ng-href=="www.google.com" href=""www.google.com" /a>
这里我想在调用该函数时用“www.yahoo.com”更新网址。
答案 0 :(得分:1)
问题在于锚标签有双==而没有&#34;&#34;周围。请参阅下面的更新示例:
<a ng-href="{{selectedValue}}">Link Name</a>
$scope.selectedValue = "www.google.com";
$scope.otherButtonFn = function(){
$scope.selectedValue = "www.yahoo.com";
}
答案 1 :(得分:0)
angular.module('myApp',[])
.controller('TestCtrl', function($scope){
$scope.something = "somewhere";
$scope.changeSomething = function(){
$scope.something = "somewhere else";
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="TestCtrl">
<a ng-href="{{something}}">{{something}}</a>
<button ng-click="changeSomething()">Change</button>
</div>
</div>
无法重现上述问题。