【问题标题】:Changing States with AngularJS using element from an array使用数组中的元素使用 AngularJS 更改状态
【发布时间】:2018-06-11 00:26:12
【问题描述】:

我有一个充满文章的数组,显示一个元素:

$scope.articles = [];

//New article
var article = {};
article.heading = "A DISCUSSION WITH ATHEISTS ON EVOLUTION";
article.date = "December 24, 2017";
article.description = "The point of my discussion was to attempt to convince a relatively large group of atheists in r/DebateAnAtheist that the theory of evolution which they hold on to so dearly is in fact a random process. It is generally maintained that evolution is not random due to natural selection. This idea, however, is fundamentally flawed.";
article.link = "evolution-debate";
article.img = "templates/articles/evolution-debate/darwin.jpg";
//Add to array
$scope.articles.push(article);

我想将我的状态更改为进化辩论状态:

.state("evolution-debate", {
        url: "/evolution-debate",
        templateUrl: "templates/articles/evolution-debate.html",
        controller: 'articles'
    })

但由于我从数组加载文章,我需要使用数组对象中的 article.link 属性更改状态。

我目前正在使用这段代码,但它不会改变状态:

<ul class="actions">
     <li><a ng-click="go('{{article.link}}')" class="button big">READ NOW</a></li>
 </ul>

任何帮助将不胜感激。

【问题讨论】:

  • 您可以使用 立即阅读 导航到您的文章
  • 我很高兴能够提供帮助。如果有人遇到类似问题,还可以添加作为答案,比 cmets 更容易遵循答案。

标签: javascript html angularjs html5-canvas


【解决方案1】:

您可以使用 ui-sref 导航到您的文章

<a ui-sref="{{article.link}}">READ NOW</a> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 2021-04-07
    • 2021-12-25
    • 2021-11-13
    • 1970-01-01
    相关资源
    最近更新 更多