javascript - AngularJS 在 div 中使用 ng-click

标签 javascript html angularjs model-view-controller ionic-framework

我无法让 ng-click 工作,我试图在 div 中将 url 传递给它,这样当用户单击它时它会转到下一页,但是当我单击 div 时我可以看到它获得了正确的链接,但没有转到下一页,而是返回了主页。

<div ng-repeat="contatosCliente in contatos" class="conteudo" type="item-link" ng-click="urlcontato('#/app/contatos/' + contatosCliente.contatos_id)">
                     {{contatosCliente.nome}}
                    <i class="ion-ios-arrow-right" style="border: none; padding-right: 11px"></i>

                </div>

还有我的 Controller :

 $scope.urlcontato = function ( path ) {
            $location.path( path );
        };

最佳答案

$location.path 应该只用一个正斜杠调用,没有那个散列。

https://docs.angularjs.org/api/ng/service/$location

<div ng-repeat="contatosCliente in contatos" class="conteudo" type="item-link" ng-click="urlcontato('/app/contatos/' + contatosCliente.contatos_id)">

并且您应该检查以确保您的 View 绑定(bind)到您的 Controller 。在您的函数中添加一些日志记录,或使用调试器语句,以确保正在调用 urlcontato

关于javascript - AngularJS 在 div 中使用 ng-click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29085781/

相关文章:

javascript - 是否可以检查 Angular 应用程序是否已经有正在运行的应用程序模块?

AngularJS - 将工厂从另一个模块注入(inject)提供者

javascript - 类内的 if 语句

javascript - javascript中如何将多个对象转换为键值对的Array[]

javascript - 使用 Web Audio API 缓冲音频

javascript - 如何使用 if 语句启动/停止和重置 setInterval 动画?

javascript - Ajax调用向div添加更多内容

javascript - Javascript 中第一行列的 getElementsByTagName

html - 元标签 itemprop

angularjs - 同步 AngularJS 函数