Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/services/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ function mdCompilerService($q, $http, $injector, $compile, $controller, $templat
var template = options.template || '';
var controller = options.controller;
var controllerAs = options.controllerAs;
var resolve = options.resolve || {};
var locals = options.locals || {};
var resolve = angular.copy(options.resolve || {});
var locals = angular.copy(options.locals || {});
var transformTemplate = options.transformTemplate || angular.identity;
var bindToController = options.bindToController;

Expand Down
50 changes: 32 additions & 18 deletions src/core/services/compiler/compiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,41 @@ describe('$mdCompiler service', function() {
expect(data.element.html()).toBe('hello world');
});

it('resolve and locals should work', function() {
module(function($provide) {
$provide.constant('StrawberryColor', 'red');
});
describe('with resolve and locals options', function() {
var options;

var data = compile({
resolve: {
//Resolve a factory inline
fruit: function($q) {
return $q.when('apple');
beforeEach(function() {
module(function($provide) {
$provide.constant('StrawberryColor', 'red');
});

options = {
resolve: {
//Resolve a factory inline
fruit: function($q) {
return $q.when('apple');
},
//Resolve a DI token's value
color: 'StrawberryColor'
},
//Resolve a DI token's value
color: 'StrawberryColor'
},
locals: {
vegetable: 'carrot'
}
locals: {
vegetable: 'carrot'
}
};
});

it('should work', function() {
var data = compile(options);
expect(data.locals.fruit).toBe('apple');
expect(data.locals.vegetable).toBe('carrot');
expect(data.locals.color).toBe('red');
});

it('should not overwrite the original values', function() {
var clone = angular.copy(options);
compile(options);
expect(options).toEqual(clone);
});
expect(data.locals.fruit).toBe('apple');
expect(data.locals.vegetable).toBe('carrot');
expect(data.locals.color).toBe('red');
});

describe('after link()', function() {
Expand Down