Why doesn't the angular directive work when bracket follow under return?
app.directive("alert", function () {
return
{
restrict: "EA",
template: "<div>Alert!!</div>"
};
});
But does work when the bracket is adjacent to the return:
app.directive("alert", function () {
return {
restrict: "EA",
template: "<div>Alert!!</div>"
};
});
Because when you just have return that considered to be return nothing undefined(nothing). You must return something on same line otherwise its same as that of return;
& when you have it on same line it considered as you returned object(DDO) from directive.
That's because JavaScript will take return as a single operation, this because return by itself is a valid operation.
First example would be the same thing as having
app.directive("alert", function () {
return;
{
restrict: "EA",
template: "<div>Alert!!</div>"
};
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With