ng-click 在带有参数的函数调用中给出 "href undefined " 错误
ng-click gives "href undefined " error on a function call with a parameter
在看到与此相关的多个问题后,我仍然无法弄清楚为什么会发生错误。
到目前为止,这是我的代码:
app.js
myApp.controller("myController", function($scope, $window) {
$scope.redirectto = function (id) {
if(id === 'test') {
$window.location.href = "http://mydomain.test.com/";
}
};
};
html 文件:
<div layout="column" flex=40 layout-align="center center"
ng-click="redirectto('test')" role="button"><span>Test</span>
</div>
看起来没有什么复杂的东西 here.But 当我使用 grunt 构建源代码时,我收到以下错误。
TypeError: Cannot set property 'href' of undefined
$location.path('http://mydomain.test.com/');
在您的完整代码中,它将是:
myApp.controller("myController", function($scope, $location) {
$scope.redirectto = function (id) {
if(id === 'test') {
$location.path('http://mydomain.test.com/');
}
};
};
在看到与此相关的多个问题后,我仍然无法弄清楚为什么会发生错误。
到目前为止,这是我的代码:
app.js
myApp.controller("myController", function($scope, $window) {
$scope.redirectto = function (id) {
if(id === 'test') {
$window.location.href = "http://mydomain.test.com/";
}
};
};
html 文件:
<div layout="column" flex=40 layout-align="center center"
ng-click="redirectto('test')" role="button"><span>Test</span>
</div>
看起来没有什么复杂的东西 here.But 当我使用 grunt 构建源代码时,我收到以下错误。
TypeError: Cannot set property 'href' of undefined
$location.path('http://mydomain.test.com/');
在您的完整代码中,它将是:
myApp.controller("myController", function($scope, $location) {
$scope.redirectto = function (id) {
if(id === 'test') {
$location.path('http://mydomain.test.com/');
}
};
};