gpt4 book ai didi

angularjs - 我可以在字符串中有 Angular ng-href 绑定(bind)变量吗

转载 作者:行者123 更新时间:2023-12-04 23:48:37 26 4
gpt4 key购买 nike

我想将链接 href 属性绑定(bind)到 Controller 中的变量,但我也希望将该 url 绑定(bind)到变量。我想使用内置绑定(bind)来完成此操作,而无需手动查看更改并重新加载 url。这可能吗?

// In the controller
$scope.section = 'section1';
$scope.page = 'page1';
$scope.url = 'http://myurl/{{section}}/{{page}}';


<!-- In the template -->
<a ng-href="{{url}}">Page Link</a>

这是我实际代码的简化。在模板中声明 url 模式会起作用,但我需要在传入的字符串中定义 url。

最佳答案

只需设置 ng-href

<a ng-href="http://myurl/{{section}}/{{page}}">Page Link</a>

关于angularjs - 我可以在字符串中有 Angular ng-href 绑定(bind)变量吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28096829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com