Pass values between policies

2

I'm starting with angular and I have a question. I have the following scenario: I created a directive with the responsibility of displaying message on the screen. Below her code.

message.js

"use strict";

angular.module("layout")
.directive('mensagem', function () {
    return {
        restrict: 'EA',
        templateUrl: '/Marcenaria/Scripts/App/Directive/Layout/mensagem.html',
        scope:{
            msgSucesso: '@',
            msgError: '@',
            msgInfo: '@'
        }
    }
});

message.html

<div ng-if="msgSucesso" class="alert alert-success alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <h4>    <i class="icon fa fa-check"></i> Sucesso!</h4>
    {{msgSucesso}}
</div>
<div ng-if="msgError" class="alert alert-warning alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <h4>    <i class="icon fa fa-warning"></i> Atenção!</h4>
    {{msgError}}
</div>
<div ng-if="msgInfo" class="alert alert-info alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <h4><i class="icon fa fa-info"></i> Informativo!</h4>
    {{msgInfo}}
</div>

Policy call

 <mensagem msgError="{{msgError}}" msgSucesso="{{msgSucesso}}" msgInfo="{{msgInfo}}"></mensagem>

The question is, when I update msgError, for example, that information is not updated within the message directive and therefore does not print the message on the screen, how do I resolve it?

    
asked by anonymous 27.10.2015 / 01:32

1 answer

2

To solve the problem, it was necessary to change the @ 's by = and change the name of the attributes in the message directive, because the names with camel case were giving problem.

"use strict";

angular.module("layout")
.directive('mensagem', function () {
    return {
        restrict: 'EA',
        templateUrl: '/Marcenaria/Scripts/App/Directive/Layout/mensagem.html',
        scope:{
            sucesso: '=',
            error: '=',
            info: '='
        }
    }
});

Call:

<mensagem error="{{msgError}}" sucesso="{{msgSucesso}}" info="{{msgInfo}}"></mensagem>
    
27.10.2015 / 02:08