Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ng单击不在引导ng包含中工作_Javascript_Angularjs_Angularjs Ng Include - Fatal编程技术网

Javascript ng单击不在引导ng包含中工作

Javascript ng单击不在引导ng包含中工作,javascript,angularjs,angularjs-ng-include,Javascript,Angularjs,Angularjs Ng Include,事实上,我有一个ng include引导程序 <a data-href="#/speakers/{{speaker.id}}" ng-click="myFunc('{{speaker.id}}')"> <span class="speaker-name">{{speaker.name}}</span> <span class="speaker-title-company">{{speaker.title}}, {{speaker.c

事实上,我有一个ng include引导程序

<a data-href="#/speakers/{{speaker.id}}" ng-click="myFunc('{{speaker.id}}')">
    <span class="speaker-name">{{speaker.name}}</span>
    <span class="speaker-title-company">{{speaker.title}}, {{speaker.company}}</span>
</a>
增强

var self = this;

angular.module(this.constructor.NAME, [])
.controller("SpeakerController", function($scope, $location){self.speakerController($scope, $location)})
angular.bootstrap(document.getElementById("speakers"), [this.constructor.NAME]);
然后是扬声器控制器

speakerController: function($scope, $location) {
    var self = this;

    $scope.myFunc = function(param){console.log('in');self.myFunc(param)}
},

myFunc: function(param) {
    console.log(param);  
},

更改为
ng单击=“myFunc(speaker.id)”
。您不需要在那里使用表达式。

太棒了,我如何传递
data href=“#/speakers/{{speaker.id}”
基本上是myFunc(url)函数的url,链接应该是#/speakers/1、#/speakers/2、#/speakers/3等。或者在这个世界中,这是什么最好的方式,由于某种原因,我不得不在代码中使用
window.location=url
。我建议您按原样传递变量,并在函数中附加静态部分。但是如果您坚持,
ng click=“MyFunc('#/speakers/'+speaker.id)”
我查找了$event.target,但问题是,href在父元素上,而$event.target在我的示例中是
标记,但我的锚中有hg click setup,是否有类似$this的东西?因此,我将$event和来自锚点($this)的getAttribute('data-href')传递给锚点本身,因为在锚点上可能会定义更多属性。我不知道这个
$event.$target
在哪里,但无论如何,这听起来像是一个不同的问题,您应该发布。
speakerController: function($scope, $location) {
    var self = this;

    $scope.myFunc = function(param){console.log('in');self.myFunc(param)}
},

myFunc: function(param) {
    console.log(param);  
},