Angularjs - Pass argument to directive

后端 未结 6 1128
日久生厌
日久生厌 2020-12-04 19:08

Im wondering if there is a way to pass an argument to a directive?

What I want to do is append a directive from the controller like this:

$scope.titl         


        
6条回答
  •  天涯浪人
    2020-12-04 19:33

    Controller code

    myApp.controller('mainController', ['$scope', '$log', function($scope, $log) {
        $scope.person = {
            name:"sangeetha PH",
           address:"first Block"
        }
    }]);
    

    Directive Code

    myApp.directive('searchResult',function(){
       return{
           restrict:'AECM',
           templateUrl:'directives/search.html',
           replace: true,
           scope:{
               personName:"@",
               personAddress:"@"
           }
       } 
    });
    

    USAGE

    File :directives/search.html
    content:

    {{personName}}

    {{personAddress}}

    the File where we use directive

    
    

提交回复
热议问题