我在ng-repeater中有一个指令应该设置一个范围属性.请看这里的小提琴:http://jsfiddle.net/paos/CSbRB/
问题是scope属性是作为属性值给出的,如下所示:
<button ng-update1="inputdata.title">click me</button>
Run Code Online (Sandbox Code Playgroud)
该指令应该将scope属性inputdata.title设置为某个字符串.这不起作用:
app.directive('ngUpdate1', function() {
return function(scope, element, attrs) {
element.bind('click', function() {
scope.$apply(function() {
scope[ attrs.ngUpdate1 ] = "Button 1";
});
});
};
});
Run Code Online (Sandbox Code Playgroud)
但是,直接分配工作:
scope["inputdata"]["title"] = "Button 1";
Run Code Online (Sandbox Code Playgroud)
你能告诉我如何设置范围属性吗?指令中的符号表示法?
PS:小提琴使用转发器的原因是因为它使指令在子范围内.当它们位于子作用域中时,您无法写入作为基元的作用域属性.这就是为什么我需要一个带有"."的对象属性.在名字里.请参阅此处的详细解释:AngularJS中范围原型/原型继承的细微差别是什么?
谢谢
在查询$ httpBackend后我似乎无法返回预期的结果,我不知道测试有什么问题.你能看一下这个失败的最小例子吗?
http://jsfiddle.net/paos/kTNF5/
query() Expected [ ] to equal [ { hello : 'world' } ].
Run Code Online (Sandbox Code Playgroud)
<script src="https://raw.github.com/pivotal/jasmine/master/lib/jasmine-core/jasmine.js"></script>
<script src="https://raw.github.com/pivotal/jasmine/master/lib/jasmine-core/jasmine-html.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular-resource.min.js"></script>
<script src="http://code.angularjs.org/1.0.1/angular-mocks-1.0.1.js"></script>
Run Code Online (Sandbox Code Playgroud)
测试javascript
var mod = angular.module('mod', ['ngResource']);
mod.factory('Brief', function($resource) {
var Brief = $resource('http://some_test/:id');
return Brief;
});
beforeEach(function() {
module('mod');
inject(function($injector) {
resource = $injector.get('$resource');
$httpBackend = $injector.get('$httpBackend');
Brief = $injector.get('Brief');
});
});
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
describe("Brief", function() {
it("query()", function() {
var getRequest = 'http://some_test';
var fakeGetResponse = …Run Code Online (Sandbox Code Playgroud) 我需要创建一个应用程序,可以检测何时使用chrome developer工具更新网页上的属性.例如,如果我调出开发人员工具,请使用元素选择器并更改特定元素的字体大小(参见图片).我应该能够运行一个程序,通知页面上更新了哪些元素,以及更改了哪些属性.
怎么可能这样呢?
