我是AngularJS的新手,我点击ng-repeat生成的单选按钮,点击事件拒绝触发.如果我使用简单的onclick,那确实有效.
这有效,我看到警报:
<div class="span2 left-justify"
ng-repeat="choice in physicalmode_choices">
<input type="radio"
name="physical_layer"
value="{{ choice.private }}"
onclick="alert('foo')"
required
ng-model="$parent.networkoptions.physicalmode" />
<span ng-bind="choice.public"></span>
</div>
Run Code Online (Sandbox Code Playgroud)
但这不是:
<div class="span2 left-justify"
ng-repeat="choice in physicalmode_choices">
<input type="radio"
name="physical_layer"
value="{{ choice.private }}"
ng-click="alert('foo')"
required
ng-model="$parent.networkoptions.physicalmode" />
<span ng-bind="choice.public"></span>
</div>
Run Code Online (Sandbox Code Playgroud)
我不能用ng-click做到这一点吗?或者我误解了"表达"是什么?
谢谢,迈克
我目前正在与Angular合作并使用Karma和Jasmine进行测试.例如,过滤器被注入主模块并且可以毫无问题地进行测试,但是当我尝试测试控制器时,我在注入后得到一个空对象.
这是我的主要模块的代码:
(function () {
'use strict';
var dependencies = [];
angular.module('myApp', dependencies)
}());
Run Code Online (Sandbox Code Playgroud)
我要测试的控制器:
(function () {
'use strict';
angular.module('myApp')
.controller('NavCtrl', ['$scope',
function ($scope) {
$scope.currentUser = null;
}]);
}());
Run Code Online (Sandbox Code Playgroud)
最后是测试套件:
describe ("controller", function() {
beforeEach(module("myApp"));
var $scope, $rootScope, controllerLoader;
beforeEach(inject(function($injector) {
$rootScope = $injector.get('$rootScope');
$scope = $rootScope.$new();
var $controller = $injector.get('$controller');
controllerLoader = function() {
return $controller('NavCtrl', {
'$scope': $scope
});
};
}));
it ("testing injection", function() {
var controller = controllerLoader();
expect(controller).toNotEqual({});
}) …Run Code Online (Sandbox Code Playgroud)