angular.js - How do angular directives assign values ​​to controls?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-15 17:05:14
0
3
586

For example, I have a parameter in the main controller: $scope.datas

Then, I have a directive here that requests data on the accused controller and then wants to assign the value to the main controller's $scope.datas.
How to succeed?

For example, command:


app.directive('profitSearch', function () {

    return {

        restrict: 'AE',
        scope: {
            datas: "="
        },
        templateUrl: "/templates/profitSearch.jsp",
        controller: function ($scope, $http) {

        $http({
                    url: 'doSearch.req',
                    method: 'POST',
                    data: $scope.searchObject
                }).success(function (response, header, config, status) {

                    $scope.datas = response.content;

                }).error(function (response, header, config, status) {


                });

}

The command is applied directly on the page:

<profit-search></profit-search>

But this assignment is wrong:
$compile:nonassign

How to break it? Didn’t I use two-way binding above?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(3)
曾经蜡笔没有小新

There is no value assigned when you use it in the command. Try changing it to this.

 scope: {
    datas: "=?"
 },

Or assign a value to the command

<profit-search datas="datas"></profit-search>

https://docs.angularjs.org/error/$compile/nonassign

仅有的幸福

Do you need to write instructions? Recklessly! Not only does it waste time by writing instructions randomly, the performance will not be better. Writing a request directly in the service should solve the problem.

Peter_Zhu
<profit-search datas='datas'></profit-search>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template