我继承了一个使用Angular.js的网站,它有一些跟踪Google Analytics的功能。出于某种原因,如果在加载初始视图后创建任何ng-click项目,则不会触发任何ng-click项目。页面的工作原理:
如上所述,ng-click不会触发。以下是代码的相关部分:
angular.module("backinfocus").controller("DoctorDetail", ["$scope", "$http", "$window", "$q",
function(n, t, i, r) {
function u(n, t) {
t = t || r.defer();
var i = f(n);
return e.geocode({
address: i
}, function(i, r) {
if (r == google.maps.GeocoderStatus.OK) {
var f = i[0].geometry.location;
t.resolve({
address: n,
location: f
})
} else r == google.maps.GeocoderStatus.OVER_QUERY_LIMIT ? setTimeout(function() {
u(n, t)
}, 1e3) : t.reject(r)
}), t.promise
}
n.trackWebsite = function() {
var t = n.result,
i = n.selectedAddress;
trackEvent("Doc Finder", "Details Page-Click View Website Button", t.doctorId + ", " + t.name + ", " + i.website)
};
n.trackDirections = function() {
var i = n.result,
t = n.selectedAddress;
trackEvent("Doc Finder", "Details Page-Click Driving Directions Button", i.doctorId + ", " + i.name + ", " + t.name + " " + t.address1 + " " + t.address2 + ", " + t.city + ", " + t.state + " " + t.zipCode)
};
}
]);
HTML:
<div class="col-sm-4 col-md-3">
<div class="result_contact">
<span ng-if="result.TollPhone">Toll-free: {{result.TollPhone}}<br></span>
<span ng-if="result.LocalPhone">Phone: {{result.LocalPhone}}<br></span>
<a ng-if="result.Website" href="" ng-href="{{result.Website}}" target="_blank" title="{{result.Website}}" ng-click="trackWebsite(result);">View Website</a>
</div>
</div>
知道为什么这不会开火? Javascript函数没有参数但代码传递参数是否重要?这可能是问题吗?
顺便提一下,控制台显示我似乎无法理解的错误:
ReferenceError:未定义地址 在h.n.trackWebsite(app.js:300) 在Za.functionCall(angular.js:10348) 在angular.js:18333 at h。$ get.h. $ eval(angular.js:12175) at h。$ get.h. $ apply(angular.js:12273) 在HTMLAnchorElement。 (angular.js:18332) 在HTMLAnchorElement.v.event.dispatch(jquery-1.8.3.min.js:2) 在HTMLAnchorElement.v.event.add.o.handle.u(jquery-1.8.3.min.js:2)(匿名函数)@ angular.js:9563 $ get @ angular.js:7004 $ get.h。 $ apply @ angular.js:12275(匿名函数)@ angular.js:18332v.event.dispatch @jquery-1.8.3.min.js:2v.event.add.o.handle.u @jquery-1.8.3 .min.js:2
有什么想法吗?