I created my first directive in Angular running in the file structure of the high.js 0.4-dev file, which I automatically generated using Yeoman.
The directive compiles correctly when I use the "template:" property, however, when I try to move the contents to the template file and use the "templateUrl:" property, it loads the uncompiled layout.server.view.html 'file instead of the' contact-form file. client.template.html '. It seems that it cannot find my template file no matter what I set the path for (I tried all the paths up the tree).
Can anyone see what I'm doing wrong. Perhaps someone can explain how Angular resolves relative paths.
My program structure looks like this ... I generated a module for the contact form using a 0.4-dev generator mean. The module contains my directive. My file structure is as follows:
/app
/config
/modules
/contact-forms
/client
/config
/controllers
contact-forms.client.controller.js
/views
contact-form.client.template.html <- 2. should load this
contact-forms.client.module.js
/core
/client
/views
home.client.view.html <- 1. <contact-form> directive here
/server
/controllers
/routes
/views
layout.server.view.html <- 3. instead loads this
/node_modules
/public
/uploads
My directive code is:
contactForms.directive('contactForm',[function(){
return {
restrict: 'E',
transclude: 'true',
templateUrl: 'modules/contact-forms/client/views/contact-form.client.template.html'
};
}]);
And my template file looks like this:
<div>
<form class="row col-md-6 col-md-offset-3 text-left">
<div class="form-group col-md-12">
<label for="Name">Name</label>
<input type="text" class="form-control" id="inputName">
</div>
<div class="form-group col-md-12">
<label for="email">Email</label>
<input type="email" class="form-control" id="inputEmail">
</div>
<div class="form-group col-xs-12">
<label for="emailSubject">Subject</label>
<input type="text" class="form-control" id="inputSubject">
</div>
<div class="form-group col-xs-12">
<label for="emailMessage">Message</label>
<input type="text" class="form-control" id="inputMessage">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
I saw several posts on this type of problem, but none of them matched my use case. I am running a local express server, so I do not think this post is a problem ( Failed to load the template using templateUrl in Angularjs ).
This post says templateUrl is wrong, but I think my correct one ( Angular templateURL directive doesn't load. Why? )
Angular github (https://github.com/angular/angular.js/issues/10965), angular.js . feb 4 , . , , .
node.js Yeoman mean.js:
module.exports = function(app) {
var core = require('../controllers/core.server.controller');
app.route('/server-error').get(core.renderServerError);
app.route('/not-found').get(core.renderNotFound);
app.route('/*').get(core.renderIndex);
};
'use strict';
exports.renderIndex = function(req, res) {
res.render('modules/core/server/views/index', {
user: req.user || null
});
};
exports.renderServerError = function(req, res) {
res.status(500).render('modules/core/server/views/500', {
error: 'Oops! Something went wrong...'
});
};
exports.renderNotFound = function(req, res) {
res.status(404).render('modules/core/server/views/404', {
url: req.originalUrl
});
};
?